Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.comphenix.testing;
- import com.comphenix.testing.BlockChangeArray.BlockChange;
- import com.google.caliper.Runner;
- import com.google.caliper.SimpleBenchmark;
- /*
- * RESULT:
- *
- * 0% Scenario{vm=java, trial=0, benchmark=Normal} 2,87 ns; ?=0,02 ns @ 3 trials
- * 50% Scenario{vm=java, trial=0, benchmark=Recycle} 3,33 ns; ?=0,23 ns @ 10 trials
- *
- * benchmark ns linear runtime
- * Normal 2,87 =========================
- * Recycle 3,33 ==============================
- *
- * vm: java
- * trial: 0
- */
- class Test {
- public static class Benchmark extends SimpleBenchmark {
- private BlockChangeArray array = new BlockChangeArray(100);
- public int timeNormal(int reps) {
- for (int i = 0; i < reps; i++) {
- BlockChange change = array.getBlockChange(i % 100);
- change.setBlockID(change.getBlockID() + 1);
- }
- return array.getBlockChange(0).getBlockID();
- }
- public int timeRecycle(int reps) {
- BlockChange reused = null;
- for (int i = 0; i < reps; i++) {
- reused = array.getBlockChange(i % 100, reused);
- reused.setBlockID(reused.getBlockID() + 1);
- }
- return array.getBlockChange(0).getBlockID();
- }
- }
- public static void main(String[] args) throws Exception {
- Runner.main(Benchmark.class, args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement