Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-47 [created] 6d2f81a8e


# ignite-47 Add method GridTestUtil.benchmark()


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/ce2d2663
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ce2d2663
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ce2d2663

Branch: refs/heads/ignite-47
Commit: ce2d2663f868174c4d19e018f698e4e7b633ca5e
Parents: bf4203f
Author: sevdokimov <sergey.evdoki...@jetbrains.com>
Authored: Sat Mar 7 14:31:50 2015 +0300
Committer: sevdokimov <sergey.evdoki...@jetbrains.com>
Committed: Sat Mar 7 14:31:50 2015 +0300

----------------------------------------------------------------------
 .../ignite/testframework/GridTestUtils.java     | 50 ++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce2d2663/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java 
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 6175a2f..4584f84 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -45,6 +45,7 @@ import java.nio.file.attribute.*;
 import java.security.*;
 import java.util.*;
 import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
 
 /**
  * Utility class for tests.
@@ -1434,6 +1435,55 @@ public final class GridTestUtils {
     }
 
     /**
+     * @param name Name.
+     * @param run Run.
+     */
+    public static void benchmark(@Nullable String name, @NotNull Runnable run) 
{
+        benchmark(name, 8000, 10000, run);
+    }
+
+    /**
+     * @param name Name.
+     * @param warmup Warmup.
+     * @param executionTime Time.
+     * @param run Run.
+     */
+    public static void benchmark(@Nullable String name, long warmup, long 
executionTime, @NotNull Runnable run) {
+        final AtomicBoolean stop = new AtomicBoolean();
+
+        class Stopper extends TimerTask {
+            @Override public void run() {
+                stop.set(true);
+            }
+        }
+
+        new Timer(true).schedule(new Stopper(), warmup);
+
+        while (!stop.get())
+            run.run();
+
+        stop.set(false);
+
+        new Timer(true).schedule(new Stopper(), executionTime);
+
+        long startTime = System.currentTimeMillis();
+
+        int cnt = 0;
+
+        do {
+            run.run();
+
+            cnt++;
+        }
+        while (!stop.get());
+
+        double dur = (System.currentTimeMillis() - startTime) / 1000d;
+
+        System.out.printf("%s:\n operations:%d, duration=%fs, op/s=%d, 
latency=%fms\n", name, cnt, dur,
+            (long)(cnt / dur), dur / cnt);
+    }
+
+    /**
      * @return Path to apache ignite.
      */
     public static String apacheIgniteTestPath() {

Reply via email to