Java 类org.openjdk.jmh.annotations.Setup 实例源码

项目:buffer-slayer    文件:AbstractBatchJdbcTemplateBenchmark.java   
@Setup
public void setup() throws PropertyVetoException {
  dataSource = new DriverManagerDataSource();
  dataSource.setDriverClassName("com.mysql.jdbc.Driver");
  dataSource.setUrl(propertyOr("jdbcUrl", "jdbc:mysql://127.0.0.1:3306?useSSL=false"));
  dataSource.setUsername(propertyOr("username", "root"));
  dataSource.setPassword(propertyOr("password", "root"));

  JdbcTemplate delegate = new JdbcTemplate(dataSource);
  delegate.setDataSource(dataSource);

  proxy = new SenderProxy(new JdbcTemplateSender(delegate));
  proxy.onMessages(updated -> counter.addAndGet(updated.size()));

  reporter = reporter(proxy);
  batch = new BatchJdbcTemplate(delegate, reporter);
  batch.setDataSource(dataSource);

  unbatch = new JdbcTemplate(dataSource);
  unbatch.setDataSource(dataSource);
  unbatch.update(CREATE_DATABASE);
  unbatch.update(DROP_TABLE);
  unbatch.update(CREATE_TABLE);
}
项目:alog    文件:AlogBenchmark.java   
@Setup
public void start() {
    counter = 0;
    if (log == null) {
        System.setProperty(
                "Log4jContextSelector",
                "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
        LoggerContext context = LoggerContext.getContext();
        log = context.getLogger("Log4j2");
        log.setAdditive(false);
        ArrayList<Appender> list = new ArrayList<Appender>();
        list.addAll(log.getAppenders().values());
        for (Appender a : list) {
            log.removeAppender(a);
        }
    }
}
项目:jvm-dynamic-optimizations-performance-test    文件:Nullness.java   
@Setup
public void setup() {
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    executor.schedule(
            () -> {
                System.out.println("Deoptimize: 1");
                state = 1;
            },
            25, TimeUnit.SECONDS);
    executor.schedule(
            () -> {
                System.out.println("Deoptimize :0");
                state = 0;
            },
            30, TimeUnit.SECONDS);
}
项目:reactor-ntp-clock    文件:TimeMeasurementBenchmarks.java   
@Setup
public void setup() {
  NTPUDPClient client = new NTPUDPClient();
  ZoneId zoneId = ZoneId.systemDefault();
  List<String> ntpHosts = Arrays.asList("0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org");
  int pollIntvl = 8_000;

  clockWithCaching = new NTPClock(
      "cached-ntp-clock-benchmark",
      zoneId,
      ntpHosts,
      client,
      pollIntvl,
      150
  );
  clockWithoutCaching = new NTPClock(
      "uncached-ntp-clock-benchmark",
      ZoneId.systemDefault(),
      ntpHosts,
      client,
      pollIntvl,
      0
  );

  nanoTimeStart = System.nanoTime();
}
项目:hekate    文件:MultiNodeBenchmarkContext.java   
@Setup
public void setUp() throws HekateFutureException, InterruptedException {
    nodes = new ArrayList<>(nodesCount);

    for (int i = 0; i < nodesCount; i++) {
        HekateBootstrap boot = new HekateBootstrap()
            .withNodeName("node" + i)
            .withDefaultCodec(new KryoCodecFactory<>())
            .withService(new LocalMetricsServiceFactory());

        configure(i, boot);

        Hekate node = boot.join();

        nodes.add(node);
    }

    initialize(nodes);
}
项目:yuvi    文件:OffHeapVarBitMetricStoreBuildBenchmark.java   
@Setup(Level.Trial)
public void setup() {
  chunkStore = new ChunkImpl(
      new MetricsAndTagStoreImpl(new InvertedIndexTagStore(1_000_000, 1_000_000), new VarBitMetricStore()), null);

  try (Stream<String> lines = Files.lines(filePath, Charset.defaultCharset())) {
    lines.forEachOrdered(line -> {
      try {
        String[] words = line.split(" ");
        String metricName = words[1];
        if (counts.containsKey(metricName)) {
          counts.put(metricName, counts.get(metricName) + 1);
        } else {
          counts.put(metricName, 1);
        }

        MetricUtils.parseAndAddOpenTsdbMetric(line, chunkStore);
      } catch (Exception e) {
      }
    });
  } catch (Exception e) {
    e.printStackTrace();
  }
}
项目:XXXX    文件:RealRequestBenchmarks.java   
@Setup
public void setup() {
  server = RxNetty.createHttpServer(SERVER_PORT, new RequestHandler<ByteBuf, ByteBuf>() {
    public rx.Observable handle(HttpServerRequest<ByteBuf> request,
                                HttpServerResponse<ByteBuf> response) {
      return response.flush();
    }
  });
  server.start();
  client = new OkHttpClient();
  client.setRetryOnConnectionFailure(false);
  okFeign = Feign.builder()
      .client(new feign.okhttp.OkHttpClient(client))
      .target(FeignTestInterface.class, "http://localhost:" + SERVER_PORT);
  queryRequest = new Request.Builder()
      .url("http://localhost:" + SERVER_PORT + "/?Action=GetUser&Version=2010-05-08&limit=1")
      .build();
}
项目:XXXX    文件:WhatShouldWeCacheBenchmarks.java   
@Setup
public void setup() {
  feignContract = new Contract.Default();
  cachedContact = new Contract() {
    private final List<MethodMetadata> cached =
        new Default().parseAndValidatateMetadata(FeignTestInterface.class);

    public List<MethodMetadata> parseAndValidatateMetadata(Class<?> declaring) {
      return cached;
    }
  };
  fakeClient = new Client() {
    public Response execute(Request request, Request.Options options) throws IOException {
      Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
      return Response.create(200, "ok", headers, (byte[]) null);
    }
  };
  cachedFakeFeign = Feign.builder().client(fakeClient).build();
  cachedFakeApi = cachedFakeFeign.newInstance(
      new HardCodedTarget<FeignTestInterface>(FeignTestInterface.class, "http://localhost"));
}
项目:reactor-ntp-clock    文件:NTPClockBenchmarks.java   
@Setup
public void setup() {
  NTPUDPClient client = new NTPUDPClient();
  ZoneId zoneId = ZoneId.systemDefault();
  List<String> ntpHosts = Arrays.asList("0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org");
  int pollIntvl = 8_000;

  clock = new NTPClock(
      "ntp-clock-benchmark",
      zoneId,
      ntpHosts,
      client,
      pollIntvl,
      resolution
  );
}
项目:hashsdn-controller    文件:InMemoryDataStoreWriteTransactionBenchmark.java   
@Override
@Setup(Level.Trial)
public void setUp() throws Exception {
    domStore = new InMemoryDOMDataStore("SINGLE_THREADED_DS_BENCHMARK", Executors.newSingleThreadExecutor());
    schemaContext = BenchmarkModel.createTestContext();
    domStore.onGlobalContextUpdated(schemaContext);
    initTestNode();
}
项目:swage    文件:FormatBenchmarks.java   
@Setup
public void setup() {
    stringBuilders = new ArrayList<>(numStringBuilders);
    IntStream.range(0, numStringBuilders).forEach(
            i -> {
                stringBuilders.add(new StringBuilder());
            }
    );
}
项目:swage    文件:TypedMapBenchmarks.java   
@Setup
public void setup() {
    this.sink = new DataConsumer();

    dataKeys = new ArrayList<>(numDataEntries);
    IntStream.range(0, numDataEntries).forEach(
            i -> {
                dataKeys.add(TypedMap.key("Key" + rand.get().nextInt(), String.class));
            }
    );
}
项目:swage    文件:TypedMapBenchmarks.java   
@Setup
public void setup(BenchmarkParams params) {
    int numDatas = Integer.valueOf(params.getParam("numDataEntries"));

    datas = new ArrayList<>(numDatas);
    IntStream.range(0, numDatas).forEach(
            i -> {
                datas.add("rando"+rand.get().nextInt());
            }
    );
}
项目:alog    文件:AlogBenchmark.java   
@Setup(Level.Iteration)
public void start() {
    counter = 0;
    if (log == null) {
        com.comfortanalytics.alog.Alog.DEFAULT_MAX_QUEUE = -1; //ignore no messages
        log = com.comfortanalytics.alog.Alog.getLogger(
                "Alog", new PrintStream(new NullOutputStream()));
        log.getHandlers()[0].setFormatter(new SimpleFormatter());
        log.setUseParentHandlers(false);
    }
}
项目:usl4j    文件:Benchmarks.java   
@Setup
public void setup() {
  this.input = new ArrayList<>(size);
  for (int i = 0; i < size; i++) {
    input.add(Measurement.ofConcurrency().andThroughput(i, Math.random() * i));
  }
}
项目:elasticsearch_my    文件:AllocationBenchmark.java   
@Setup
public void setUp() throws Exception {
    final String[] params = indicesShardsReplicasNodes.split("\\|");

    int numIndices = toInt(params[0]);
    int numShards = toInt(params[1]);
    int numReplicas = toInt(params[2]);
    int numNodes = toInt(params[3]);

    strategy = Allocators.createAllocationService(Settings.builder()
            .put("cluster.routing.allocation.awareness.attributes", "tag")
            .build());

    MetaData.Builder mb = MetaData.builder();
    for (int i = 1; i <= numIndices; i++) {
        mb.put(IndexMetaData.builder("test_" + i)
                .settings(Settings.builder().put("index.version.created", Version.CURRENT))
                .numberOfShards(numShards)
                .numberOfReplicas(numReplicas)
        );
    }
    MetaData metaData = mb.build();
    RoutingTable.Builder rb = RoutingTable.builder();
    for (int i = 1; i <= numIndices; i++) {
        rb.addAsNew(metaData.index("test_" + i));
    }
    RoutingTable routingTable = rb.build();
    DiscoveryNodes.Builder nb = DiscoveryNodes.builder();
    for (int i = 1; i <= numNodes; i++) {
        nb.add(Allocators.newNode("node" + i, Collections.singletonMap("tag", "tag_" + (i % numTags))));
    }
    initialClusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData).routingTable(routingTable).nodes
            (nb).build();
}
项目:mumu-benchmark    文件:JMHSample_28_BlackholeHelpers.java   
@Setup
public void setup(final Blackhole bh) {
    workerBaseline = new Worker() {
        double x;

        @Override
        public void work() {
            // do nothing
        }
    };

    workerWrong = new Worker() {
        double x;

        @Override
        public void work() {
            Math.log(x);
        }
    };

    workerRight = new Worker() {
        double x;

        @Override
        public void work() {
            bh.consume(Math.log(x));
        }
    };

}
项目:mumu-benchmark    文件:JMHSample_29_StatesDAG.java   
@Setup
public synchronized void setup() {
    all = new ArrayList<>();
    for (int c = 0; c < 10; c++) {
        all.add(new Counter());
    }

    available = new LinkedList<>();
    available.addAll(all);
}
项目:mumu-benchmark    文件:JMHSample_34_SafeLooping.java   
@Setup
public void setup() {
    xs = new int[size];
    for (int c = 0; c < size; c++) {
        xs[c] = c;
    }
}
项目:mumu-benchmark    文件:JMHSample_31_InfraParams.java   
@Setup
public void setup(ThreadParams threads) {
    ids = new ArrayList<>();
    for (int c = 0; c < THREAD_SLICE; c++) {
        ids.add("ID" + (THREAD_SLICE * threads.getThreadIndex() + c));
    }
}
项目:simd-blog    文件:BenchmarkSIMDBlog.java   
@Setup
public void setup()
{
    Random random = new Random();
    for (int i = 0; i < SIZE; i++) {
        values[i] = random.nextInt(Integer.MAX_VALUE / 32);
    }
}
项目:simd-blog    文件:BenchmarkSIMDLongBlog.java   
@Setup
public void setup()
{
    Random random = new Random();
    for (int i = 0; i < SIZE; i++) {
        values[i] = random.nextLong() % (Long.MAX_VALUE / 32L);
    }
}
项目:CodeKatas    文件:IntListJMHTest.java   
@Setup
public void setUp()
{
    PrimitiveIterator.OfInt AGE_GENERATOR = new Random(1L).ints(-1000, 1000).iterator();
    final FastList<Integer> integers = FastList.newWithNValues(1_000_000, AGE_GENERATOR::nextInt);
    this.jdkList = new ArrayList<>(1_000_000);
    this.jdkList.addAll(integers);
    this.ecList = integers.collectInt(i -> i, new IntArrayList(1_000_000));

    System.out.println();
    System.out.println("Memory for ArrayList    (bytes): " + ObjectSizeCalculator.getObjectSize(this.jdkList));
    System.out.println("Memory for IntArrayList (bytes): " + ObjectSizeCalculator.getObjectSize(this.ecList));
}
项目:RxJava3-preview    文件:InputWithIncrementingInteger.java   
@Setup
public void setup(final Blackhole bh) {
    this.bh = bh;
    final int size = getSize();
    observable = Flowable.range(0, size);

    firehose = Flowable.unsafeCreate(new IncrementingPublisher(size));
    iterable = new IncrementingIterable(size);

}
项目:jvm-dynamic-optimizations-performance-test    文件:NMorphicInlinig.java   
/**
* This method modifies the test state.
* @see NMorphicInlinig#getCalculator(TestState)
*/
     @Setup
     public void setup() {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

        executor.schedule(
                () -> {
                    System.out.println("Iteration Deoptimize: 1");
                    state = 1;
                },
                25, TimeUnit.SECONDS);

        executor.schedule(
                () -> {
                    System.out.println("Iteration Deoptimize: 2");
                    state = 2;
                },
                35, TimeUnit.SECONDS);

        executor.schedule(
                () -> {
                    System.out.println("Iteration Deoptimize: 3");
                    state = 3;
                },
                160, TimeUnit.SECONDS);

        executor.schedule(
                () -> {
                    System.out.println("Iteration Deoptimize: 4");
                    state = 4;
                },
                180, TimeUnit.SECONDS);

     }
项目:java-logging-benchmarks    文件:LoggingBenchmark.java   
@Setup
public void setUp() throws IOException {
    final LogManager logManager = LogManager.getLogManager();
    try (final InputStream is = LoggingBenchmark.class.getResourceAsStream("/logging.properties")) {
        logManager.readConfiguration(is);
    }
}
项目:java-logging-benchmarks    文件:LoggingBenchmark.java   
@Setup
public void setUp() throws IOException {
    final LogManager logManager = LogManager.getLogManager();
    try (final InputStream is = LoggingBenchmark.class.getResourceAsStream("/logging.properties")) {
        logManager.readConfiguration(is);
    }
}
项目:java-logging-benchmarks    文件:LoggingBenchmark.java   
@Setup
public void setUp() throws IOException {
    final LogManager logManager = LogManager.getLogManager();
    try (final InputStream is = LoggingBenchmark.class.getResourceAsStream("/logging.properties")) {
        logManager.readConfiguration(is);
    }
}
项目:java-logging-benchmarks    文件:LoggingBenchmark.java   
@Setup
public void setUp() throws IOException {
    final LogManager logManager = LogManager.getLogManager();
    try (final InputStream is = LoggingBenchmark.class.getResourceAsStream("/logging.properties")) {
        logManager.readConfiguration(is);
    }
}
项目:xpath-to-xml    文件:DomXmlBuilderBenchmark.java   
@Setup
public void setUp() throws ParserConfigurationException {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    fixtureAccessor = new FixtureAccessor(fixtureName);
    documentBuilder = documentBuilderFactory.newDocumentBuilder();
    namespaceContext = NAMESPACE_CONTEXT_MAP.get(nsContext);
}
项目:yuvi    文件:VarBitMetricStoreBenchmark.java   
@Setup
public void setup() {
  try {
    load();
  } catch (IOException e) {
    e.printStackTrace();
  }
}
项目:yuvi    文件:ChunkManagerQueryBenchmark.java   
@Setup(Level.Trial)
public void setup() {
  ChunkManager chunkManager = new ChunkManager("test", 1_000_000);
  metricWriter = new FileMetricWriter(filePath, chunkManager);
  metricWriter.start();
  // Convert all data to offHeap
  chunkManager.toOffHeapChunkMap();
}
项目:yuvi    文件:ChunkQueryBenchmark.java   
@Setup(Level.Trial)
public void setup() {
  chunkStore = new ChunkImpl(
      new MetricsAndTagStoreImpl(new InvertedIndexTagStore(1_000_000, 1_000_000), new VarBitMetricStore()),
      null);

  try (Stream<String> lines = Files.lines(filePath, Charset.defaultCharset())) {
    lines.forEachOrdered(line -> {
      try {
        String[] words = line.split(" ");
        String metricName = words[1];
        if (metricName != null && !metricName.isEmpty()) {
          if (counts.containsKey(metricName)) {
            counts.put(metricName, counts.get(metricName) + 1);
          } else {
            counts.put(metricName, 1);
          }

          MetricUtils.parseAndAddOpenTsdbMetric(line, chunkStore);
        }
      } catch (Exception e) {
        System.err.println("Error ingesting metric: " + e.getMessage());
        e.printStackTrace();
      }
    });
  } catch (Exception e) {
    e.printStackTrace();
  }
}
项目:yuvi    文件:InvertedIndexTagStoreBenchmark.java   
@Setup(Level.Invocation)
public void setup() {
  switch (msType) {
    case "InvertedIndexTagStore":
      int initialMapSize = 10000;
      ms = new InvertedIndexTagStore(initialMapSize, initialMapSize);
      metrics = new ArrayList();
      for (int i = 0; i < initialMapSize; i++) {
        metrics.add(randomMetric(numMetrics, numKeys, numValues));
      }
      break;
    default:
      throw new RuntimeException("invalid msType: " + msType);
  }
}
项目:core-ng-demo-project    文件:HashBenchmark.java   
@Setup
public void setup() {
    values.add("abcdefghigklmnopqrstuvwxyz012345679");
    values.add("ABCDEFGHIGKLMNOPQRSTUVWXYZ012345679");
    values.add("012345679ABCDEFGHIGKLMNOPQRSTUVWXYZ");
    values.add("012345679abcdefghigklmnopqrstuvwxyz");
    values.add("012345679abcdefghigkLMNOPQRSTUvwxyz");
    values.add("012345679ABCDEFGHIGKlmnopqrstuVWXYZ");
}
项目:core-ng-demo-project    文件:URIEncodingBenchmark.java   
@Setup
public void setup() {
    pathSegments.add("path1");
    pathSegments.add("path2");
    pathSegments.add("path3");
    pathSegments.add("value1 value2");
    pathSegments.add("value1+value2");
    pathSegments.add("value1/value2");
    pathSegments.add("/value1");
    pathSegments.add("utf-8-✓");
    pathSegments.add("value1?value2");
}
项目:core-ng-demo-project    文件:StringsSplitBenchmark.java   
@Setup
public void setup() {
    texts.add("path1/path2/path3");
    texts.add("path1/path2/path3/");
    texts.add("/path1/path2/path3");
    texts.add("/long-0123456789-path1/long-0123456789-path2/long-0123456789-path3");
}
项目:core-ng-demo-project    文件:ASCIIToUpperCaseBenchmark.java   
@Setup
public void setup() {
    values.add("abcdefghigklmnopqrstuvwxyz012345679");
    values.add("ABCDEFGHIGKLMNOPQRSTUVWXYZ012345679");
    values.add("012345679ABCDEFGHIGKLMNOPQRSTUVWXYZ");
    values.add("012345679abcdefghigklmnopqrstuvwxyz");
    values.add("012345679abcdefghigkLMNOPQRSTUvwxyz");
    values.add("012345679ABCDEFGHIGKlmnopqrstuVWXYZ");
}
项目:core-ng-demo-project    文件:HTMLTemplateBenchmark.java   
@Setup
public void setup() {
    model = JSON.fromJSON(FilterUIView.class, ClasspathResources.text("template-test/filter.json"));

    Properties messages = new Properties();
    messages.load("template-test/plp_es_GT.properties");
    HTMLTemplateBuilder builder = new HTMLTemplateBuilder(new StringTemplateSource("filter", ClasspathResources.text("template-test/filter.html")), FilterUIView.class);
    builder.message = messages::get;
    template = builder.build();
}
项目:kafka-0.11.0.0-src-with-comment    文件:RecordBatchIterationBenchmark.java   
@Setup
public void init() {
    bufferSupplier = BufferSupplier.create();
    singleBatchBuffer = createBatch(1);

    batchBuffers = new ByteBuffer[batchCount];
    batchSizes = new int[batchCount];
    for (int i = 0; i < batchCount; ++i) {
        int size = random.nextInt(maxBatchSize) + 1;
        batchBuffers[i] = createBatch(size);
        batchSizes[i] = size;
    }
}