コード例 #1
0
  protected void setUpTestMapWithRandomContent(int size, int run) throws Exception {

    valueFactory = valueFactoryFactory.getInstance();

    IMapWriter writer1 = valueFactory.mapWriter();
    IMapWriter writer2 = valueFactory.mapWriter();

    int seedForThisTrial = BenchmarkUtils.seedFromSizeAndRun(size, run);
    Random rand = new Random(seedForThisTrial + 13);
    int existingValueIndex = rand.nextInt(size);

    int[] data = BenchmarkUtils.generateTestData(size, run);

    for (int i = size - 1; i >= 0; i--) {
      //			final IValue current = producer.createFromInt(data[i]);

      writer1.put(producer.createFromInt(data[i]), producer.createFromInt(data[i]));
      writer2.put(producer.createFromInt(data[i]), producer.createFromInt(data[i]));

      if (i == existingValueIndex) {
        VALUE_EXISTING = producer.createFromInt(data[i]);
      }
    }

    testMap = writer1.done();
    testMapRealDuplicate = writer2.done();

    /*
     * generate random values until a value not part of the data strucure is
     * found
     */
    while (VALUE_NOT_EXISTING == null) {
      final IValue candidate = producer.createFromInt(rand.nextInt());

      if (!testMap.containsKey(candidate)) {
        VALUE_NOT_EXISTING = candidate;
      }
    }

    testMapDeltaDuplicate =
        testMap.put(VALUE_EXISTING, VALUE_NOT_EXISTING).put(VALUE_EXISTING, VALUE_EXISTING);

    testMapRealDuplicateSameSizeButDifferent =
        testMapRealDuplicate.removeKey(VALUE_EXISTING).put(VALUE_NOT_EXISTING, VALUE_NOT_EXISTING);
  }
コード例 #2
0
  @Setup(Level.Trial)
  public void setUp() throws Exception {
    setUpTestMapWithRandomContent(size, run);

    switch (sampleDataSelection) {

        /*
         * random integers might or might not be in the dataset
         */
      case RANDOM:
        {
          // random data generator with fixed seed
          /* seed == Mersenne Prime #8 */
          Random randForOperations = new Random(2147483647L);

          for (int i = 0; i < CACHED_NUMBERS_SIZE; i++) {
            cachedNumbers[i] = producer.createFromInt(randForOperations.nextInt());
          }
        }

        /*
         * random integers are in the dataset
         */
      case MATCH:
        {
          // random data generator with fixed seed
          int seedForThisTrial = BenchmarkUtils.seedFromSizeAndRun(size, run);
          Random rand = new Random(seedForThisTrial);

          for (int i = 0; i < CACHED_NUMBERS_SIZE; i++) {
            if (i >= size) {
              cachedNumbers[i] = cachedNumbers[i % size];
            } else {
              cachedNumbers[i] = producer.createFromInt(rand.nextInt());
            }
          }

          // random data generator with fixed seed
          /* seed == Mersenne Prime #8 */
          Random anotherRand = new Random(2147483647L);

          for (int i = 0; i < CACHED_NUMBERS_SIZE; i++) {
            /*
             * generate random values until a value not part of the data
             * strucure is found
             */
            boolean found = false;
            while (!found) {
              final IValue candidate = producer.createFromInt(anotherRand.nextInt());

              if (testMap.containsKey(candidate)) {
                continue;
              } else {
                cachedNumbersNotContained[i] = candidate;
                found = true;
              }
            }
          }

          // assert (contained)
          for (IValue sample : cachedNumbers) {
            if (!testMap.containsKey(sample)) {
              throw new IllegalStateException();
            }
          }

          // assert (not contained)
          for (IValue sample : cachedNumbersNotContained) {
            if (testMap.containsKey(sample)) {
              throw new IllegalStateException();
            }
          }
        }
    }

    final IMapWriter mapWriter1 = valueFactory.mapWriter();
    mapWriter1.put(VALUE_EXISTING, VALUE_EXISTING);
    singletonMapWithExistingValue = mapWriter1.done();

    final IMapWriter mapWriter2 = valueFactory.mapWriter();
    mapWriter2.put(VALUE_NOT_EXISTING, VALUE_NOT_EXISTING);
    singletonMapWithNotExistingValue = mapWriter2.done();

    // System.out.println(String.format("\n\ncachedNumbers = %s",
    // Arrays.toString(cachedNumbers)));
    // System.out.println(String.format("cachedNumbersNotContained = %s\n\n",
    // Arrays.toString(cachedNumbersNotContained)));

    // OverseerUtils.setup(JmhMapBenchmarks.class, this);
  }