Java Code Examples for com.google.common.collect.CollectionBenchmarkSampleData.Element

The following are top voted examples for showing how to use com.google.common.collect.CollectionBenchmarkSampleData.Element. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guava-mock   File: MapBenchmark.java   View source code 6 votes vote down vote up
@Benchmark boolean get(int reps) {
  // Paranoia: acting on hearsay that accessing fields might be slow
  // Should write a benchmark to test that!
  Map<Element, Element> map = mapToTest;
  Element[] queries = this.queries;

  // Allows us to use & instead of %, acting on hearsay that division
  // operators (/%) are disproportionately expensive; should test this too!
  int mask = queries.length - 1;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    dummy ^= map.get(queries[i & mask]) != null;
  }
  return dummy;
}
 
Example 2
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 6 votes vote down vote up
@Benchmark boolean get(int reps) {
  // Paranoia: acting on hearsay that accessing fields might be slow
  // Should write a benchmark to test that!
  Map<Element, Element> map = mapToTest;
  Element[] queries = this.queries;

  // Allows us to use & instead of %, acting on hearsay that division
  // operators (/%) are disproportionately expensive; should test this too!
  int mask = queries.length - 1;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    dummy ^= map.get(queries[i & mask]) != null;
  }
  return dummy;
}
 
Example 3
Project: guava-libraries   File: MapBenchmark.java   View source code 6 votes vote down vote up
@Benchmark boolean get(int reps) {
  // Paranoia: acting on hearsay that accessing fields might be slow
  // Should write a benchmark to test that!
  Map<Element, Element> map = mapToTest;
  Element[] queries = this.queries;

  // Allows us to use & instead of %, acting on hearsay that division
  // operators (/%) are disproportionately expensive; should test this too!
  int mask = queries.length - 1;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    dummy ^= map.get(queries[i & mask]) != null;
  }
  return dummy;
}
 
Example 4
Project: guava   File: MapBenchmark.java   View source code 6 votes vote down vote up
@Benchmark
boolean get(int reps) {
  // Paranoia: acting on hearsay that accessing fields might be slow
  // Should write a benchmark to test that!
  Map<Element, Element> map = mapToTest;
  Element[] queries = this.queries;

  // Allows us to use & instead of %, acting on hearsay that division
  // operators (/%) are disproportionately expensive; should test this too!
  int mask = queries.length - 1;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    dummy ^= map.get(queries[i & mask]) != null;
  }
  return dummy;
}
 
Example 5
Project: guava   File: MapBenchmark.java   View source code 6 votes vote down vote up
@Benchmark
boolean get(int reps) {
  // Paranoia: acting on hearsay that accessing fields might be slow
  // Should write a benchmark to test that!
  Map<Element, Element> map = mapToTest;
  Element[] queries = this.queries;

  // Allows us to use & instead of %, acting on hearsay that division
  // operators (/%) are disproportionately expensive; should test this too!
  int mask = queries.length - 1;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    dummy ^= map.get(queries[i & mask]) != null;
  }
  return dummy;
}
 
Example 6
Project: guava-mock   File: SetIterationBenchmark.java   View source code 5 votes vote down vote up
@Benchmark int iteration(int reps) {
  int x = 0;

  for (int i = 0; i < reps; i++) {
    for (Element y : setToTest) {
      x ^= System.identityHashCode(y);
    }
  }
  return x;
}
 
Example 7
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = Maps.newHashMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 8
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = Maps.newLinkedHashMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 9
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = Maps.newTreeMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 10
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = new ConcurrentSkipListMap<Element, Element>();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 11
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map =
      new ConcurrentHashMap<Element, Element>(keys.size(), 0.75f, 1);
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 12
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map =
      new ConcurrentHashMap<Element, Element>(keys.size(), 0.75f, 16);
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 13
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = new MapMaker()
      .concurrencyLevel(1)
      .makeMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 14
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = new MapMaker()
      .concurrencyLevel(16)
      .makeMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 15
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  ImmutableMap.Builder<Element, Element> builder = ImmutableMap.builder();
  for (Element element : keys) {
    builder.put(element, element);
  }
  return builder.build();
}
 
Example 16
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  ImmutableSortedMap.Builder<Element, Element> builder =
      ImmutableSortedMap.naturalOrder();
  for (Element element : keys) {
    builder.put(element, element);
  }
  return builder.build();
}
 
Example 17
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@BeforeExperiment void setUp() {
  CollectionBenchmarkSampleData sampleData =
      new CollectionBenchmarkSampleData(
          isUserTypeFast, random, hitRate, size);

  if (sortedData) {
    List<Element> valueList = newArrayList(sampleData.getValuesInSet());
    Collections.sort(valueList);
    values = valueList;
  } else {
    values = sampleData.getValuesInSet();
  }
  this.mapToTest = impl.create(values);
  this.queries = sampleData.getQueries();
}
 
Example 18
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean iterateWithEntrySet(int reps) {
  Map<Element, Element> map = mapToTest;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    for (Map.Entry<Element, Element> entry : map.entrySet()) {
      dummy ^= entry.getKey() != entry.getValue();
    }
  }
  return dummy;
}
 
Example 19
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean iterateWithKeySetAndGet(int reps) {
  Map<Element, Element> map = mapToTest;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    for (Element key : map.keySet()) {
      Element value = map.get(key);
      dummy ^= key != value;
    }
  }
  return dummy;

}
 
Example 20
Project: guava-mock   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean iterateValuesAndGet(int reps) {
  Map<Element, Element> map = mapToTest;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    for (Element key : map.values()) {
      // This normally wouldn't make sense, but because our keys are our values it kind of does
      Element value = map.get(key);
      dummy ^= key != value;
    }
  }
  return dummy;

}
 
Example 21
Project: guava-mock   File: SetContainsBenchmark.java   View source code 5 votes vote down vote up
@BeforeExperiment void setUp() {
  CollectionBenchmarkSampleData sampleData =
      new CollectionBenchmarkSampleData(
          isUserTypeFast, random, hitRate, size);

  this.setToTest = (Set<Element>)impl.create(sampleData.getValuesInSet());
  this.queries = sampleData.getQueries();
}
 
Example 22
Project: guava-mock   File: SetContainsBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean contains(int reps) {
  // Paranoia: acting on hearsay that accessing fields might be slow
  // Should write a benchmark to test that!
  Set<Element> set = setToTest;
  Element[] queries = this.queries;

  int mask = queries.length - 1;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    dummy ^= set.contains(queries[i & mask]);
  }
  return dummy;
}
 
Example 23
Project: googles-monorepo-demo   File: SetIterationBenchmark.java   View source code 5 votes vote down vote up
@Benchmark int iteration(int reps) {
  int x = 0;

  for (int i = 0; i < reps; i++) {
    for (Element y : setToTest) {
      x ^= System.identityHashCode(y);
    }
  }
  return x;
}
 
Example 24
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = Maps.newHashMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 25
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = Maps.newLinkedHashMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 26
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = Maps.newTreeMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 27
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = new ConcurrentSkipListMap<Element, Element>();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 28
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map =
      new ConcurrentHashMap<Element, Element>(keys.size(), 0.75f, 1);
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 29
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map =
      new ConcurrentHashMap<Element, Element>(keys.size(), 0.75f, 16);
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 30
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = new MapMaker()
      .concurrencyLevel(1)
      .makeMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 31
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = new MapMaker()
      .concurrencyLevel(16)
      .makeMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
 
Example 32
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  ImmutableMap.Builder<Element, Element> builder = ImmutableMap.builder();
  for (Element element : keys) {
    builder.put(element, element);
  }
  return builder.build();
}
 
Example 33
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  ImmutableSortedMap.Builder<Element, Element> builder =
      ImmutableSortedMap.naturalOrder();
  for (Element element : keys) {
    builder.put(element, element);
  }
  return builder.build();
}
 
Example 34
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@BeforeExperiment void setUp() {
  CollectionBenchmarkSampleData sampleData =
      new CollectionBenchmarkSampleData(
          isUserTypeFast, random, hitRate, size);

  if (sortedData) {
    List<Element> valueList = newArrayList(sampleData.getValuesInSet());
    Collections.sort(valueList);
    values = valueList;
  } else {
    values = sampleData.getValuesInSet();
  }
  this.mapToTest = impl.create(values);
  this.queries = sampleData.getQueries();
}
 
Example 35
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean iterateWithEntrySet(int reps) {
  Map<Element, Element> map = mapToTest;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    for (Map.Entry<Element, Element> entry : map.entrySet()) {
      dummy ^= entry.getKey() != entry.getValue();
    }
  }
  return dummy;
}
 
Example 36
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean iterateWithKeySetAndGet(int reps) {
  Map<Element, Element> map = mapToTest;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    for (Element key : map.keySet()) {
      Element value = map.get(key);
      dummy ^= key != value;
    }
  }
  return dummy;

}
 
Example 37
Project: googles-monorepo-demo   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean iterateValuesAndGet(int reps) {
  Map<Element, Element> map = mapToTest;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    for (Element key : map.values()) {
      // This normally wouldn't make sense, but because our keys are our values it kind of does
      Element value = map.get(key);
      dummy ^= key != value;
    }
  }
  return dummy;

}
 
Example 38
Project: googles-monorepo-demo   File: SetContainsBenchmark.java   View source code 5 votes vote down vote up
@Benchmark boolean contains(int reps) {
  // Paranoia: acting on hearsay that accessing fields might be slow
  // Should write a benchmark to test that!
  Set<Element> set = setToTest;
  Element[] queries = this.queries;

  int mask = queries.length - 1;

  boolean dummy = false;
  for (int i = 0; i < reps; i++) {
    dummy ^= set.contains(queries[i & mask]);
  }
  return dummy;
}
 
Example 39
Project: guava-libraries   File: SetIterationBenchmark.java   View source code 5 votes vote down vote up
@Benchmark int iteration(int reps) {
  int x = 0;
  
  for (int i = 0; i < reps; i++) {
    for (Element y : setToTest) {
      x ^= System.identityHashCode(y);
    }
  }
  return x;
}
 
Example 40
Project: guava-libraries   File: MapBenchmark.java   View source code 5 votes vote down vote up
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = Maps.newHashMap();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}