ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [41/50] [abbrv] incubator-ignite git commit: # ignite-47 Add method GridTestUtil.benchmark() (cherry picked from commit ce2d266)
Date Wed, 11 Mar 2015 16:18:03 GMT
# ignite-47 Add method GridTestUtil.benchmark()
(cherry picked from commit ce2d266)


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

Branch: refs/heads/ignite-422
Commit: 2d1b861f84e29770fcebb61fa571e661f3ec38be
Parents: 5d460e0
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Sat Mar 7 14:31:50 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Wed Mar 11 18:17:36 2015 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2d1b861f/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 96b1d7a..90c6cb6 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.
@@ -1423,6 +1424,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() {


Mime
View raw message