Aleksey couldn't help with these

This commit is contained in:
Bruce Eckel 2017-01-23 14:40:55 -08:00
parent 840f7bad3c
commit bd0d56076c
6 changed files with 0 additions and 364 deletions

View File

@ -1,64 +0,0 @@
// collectiontopics/jmh/Deques.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Performance differences between Deques
package collectiontopics.jmh;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
import java.util.*;
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5, batchSize = 5000)
@Measurement(iterations = 5, batchSize = 5000)
@BenchmarkMode(Mode.SingleShotTime)
@Fork(1)
public class Deques {
private Deque<String> deque;
@Param({
"java.util.LinkedList",
"java.util.ArrayDeque",
"java.util.concurrent.ConcurrentLinkedDeque",
"java.util.concurrent.LinkedBlockingDeque",
})
private String type;
@Param({
"1",
"10",
"100",
"1000",
"10000",
"100000"
})
private int size;
@Setup
@SuppressWarnings("unchecked")
public void setup() throws Exception {
deque = (Deque<String>)
Class.forName(type).newInstance();
for(int i = 0; i < size; i++)
deque.add(Integer.toString(i));
}
@Benchmark
public Deque<String> addFirst() {
deque.addFirst("test");
return deque;
}
@Benchmark
public Deque<String> addLast() {
deque.addLast("test");
return deque;
}
@Benchmark
public String pollFirst() {
return deque.pollFirst();
}
@Benchmark
public String pollLast() {
return deque.pollLast();
}
}

View File

@ -1,94 +0,0 @@
// collectiontopics/jmh/Lists.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Performance differences between Lists
package collectiontopics.jmh;
import org.openjdk.jmh.annotations.*;
import java.util.*;
import java.util.concurrent.*;
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5, batchSize = 5000)
@Measurement(iterations = 5, batchSize = 5000)
@BenchmarkMode(Mode.SingleShotTime)
@Fork(1)
public class Lists {
private List<String> list;
@Param({
"java.util.ArrayList",
"java.util.Vector",
"java.util.LinkedList",
"java.util.concurrent.CopyOnWriteArrayList"
})
private String type;
@Param({
"1",
"10",
"100",
"1000",
"10000",
"100000"
})
private int size;
private int middle;
private ListIterator<String> it;
@Setup
@SuppressWarnings("unchecked")
public void setup() throws Exception {
list = (List<String>)
Class.forName(type).newInstance();
for(int i = 0; i < size; i++)
list.add(Integer.toString(i));
middle = size / 2;
it = list.listIterator(middle);
}
@Benchmark
public List<String> append() {
list.add("test");
return list;
}
@Benchmark
public List<String> insert() {
list.add(middle, "test");
return list;
}
@Benchmark
public String get() {
return list.get(middle);
}
@Benchmark
public List<String> set() {
list.set(middle, "test");
return list;
}
@Benchmark
public List<String> iteradd() {
try {
it.add("test");
} catch(UnsupportedOperationException e) {
System.err.println(
"-> Unsupported: listIterator.add() in " +
list.getClass().getSimpleName());
}
return list;
}
@Benchmark
public List<String> remove() {
middle = list.size() / 2;
if(middle - 1 > 0)
try {
list.remove(middle - 1);
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Out of bounds -> size: "
+ list.size() + " middle - 1: " + (middle - 1) +
" for " + list.getClass().getSimpleName());
}
return list;
}
}

View File

@ -1,72 +0,0 @@
// collectiontopics/jmh/Maps.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Performance differences between Maps
package collectiontopics.jmh;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.*;
import java.util.concurrent.*;
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5, batchSize = 5000)
@Measurement(iterations = 5, batchSize = 5000)
@BenchmarkMode(Mode.SingleShotTime)
@Fork(1)
public class Maps {
private Map<String,String> map;
@Param({
"java.util.HashMap",
"java.util.Hashtable",
"java.util.TreeMap",
"java.util.LinkedHashMap",
"java.util.IdentityHashMap",
"java.util.WeakHashMap",
"java.util.concurrent.ConcurrentHashMap",
"java.util.concurrent.ConcurrentSkipListMap",
})
private String type;
@Param({
"1",
"10",
"100",
"1000",
"10000",
})
private int size;
private String key;
@Setup
@SuppressWarnings("unchecked")
public void setup() throws Exception {
map = (Map<String,String>)
Class.forName(type).newInstance();
for(int i = 0; i < size; i++)
map.put(Integer.toString(i), Integer.toString(i));
key = Integer.toString(size / 2);
}
@Benchmark
public boolean containsKey() {
return map.containsKey(key);
}
@Benchmark
public String get() {
return map.get(key);
}
@Benchmark
public Map<String,String> put() {
map.put("test", "test");
return map;
}
@Benchmark
public void iterate(Blackhole bh) {
Iterator it = map.entrySet().iterator();
while(it.hasNext())
bh.consume(it.next());
}
}

View File

@ -1,63 +0,0 @@
// collectiontopics/jmh/Queues.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Performance differences between Queues
package collectiontopics.jmh;
import org.openjdk.jmh.annotations.*;
import java.util.*;
import java.util.concurrent.*;
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5, batchSize = 5000)
@Measurement(iterations = 5, batchSize = 5000)
@BenchmarkMode(Mode.SingleShotTime)
@Fork(1)
public class Queues {
private Queue<String> queue;
@Param({
"java.util.LinkedList",
"java.util.concurrent.ConcurrentLinkedQueue",
"java.util.concurrent.LinkedBlockingQueue",
"java.util.concurrent.LinkedTransferQueue",
"java.util.concurrent.PriorityBlockingQueue",
"java.util.PriorityQueue",
// Requires a size for construction:
//"java.util.concurrent.ArrayBlockingQueue",
// Won't accept more than one element:
//"java.util.concurrent.SynchronousQueue",
// Requires "Delayed" elements:
//"java.util.concurrent.DelayQueue",
})
private String type;
@Param({
"1",
"10",
"100",
"1000",
"10000",
"100000"
})
private int size;
@Setup
@SuppressWarnings("unchecked")
public void setup() throws Exception {
queue = (Queue<String>)
Class.forName(type).newInstance();
for(int i = 0; i < size; i++)
queue.add(Integer.toString(i));
}
@Benchmark
public Queue<String> add() {
queue.add("test");
return queue;
}
@Benchmark
public String poll() {
return queue.poll();
}
}

View File

@ -1,65 +0,0 @@
// collectiontopics/jmh/Sets.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Demonstrates performance differences in Sets
package collectiontopics.jmh;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.*;
import java.util.concurrent.*;
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5, batchSize = 5000)
@Measurement(iterations = 5, batchSize = 5000)
@BenchmarkMode(Mode.SingleShotTime)
@Fork(1)
public class Sets {
private Set<String> set;
@Param({
"java.util.HashSet",
"java.util.TreeSet",
"java.util.LinkedHashSet",
"java.util.concurrent.ConcurrentSkipListSet",
"java.util.concurrent.CopyOnWriteArraySet",
})
private String type;
@Param({
"1",
"10",
"100",
"1000",
"10000",
})
private int size;
private String key;
@Setup
@SuppressWarnings("unchecked")
public void setup() throws Exception {
set = (Set<String>)
Class.forName(type).newInstance();
for(int i = 0; i < size; i++)
set.add(Integer.toString(i));
key = Integer.toString(size/2);
}
@Benchmark
public Set<String> add() {
set.add("test");
return set;
}
@Benchmark
public boolean contains() {
return set.contains(key);
}
@Benchmark
public void iterate(Blackhole bh) {
Iterator<String> it = set.iterator();
while(it.hasNext())
bh.consume(it.next());
}
}

View File

@ -4,12 +4,6 @@ project(':validating') {
}
}
project(':collectiontopics') {
jmh {
include = 'collectiontopics.jmh.*'
}
}
project(':equalshashcode') {
dependencies {
compile project(':typeinfo')