summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/test/benchmarks/example/Makefile2
-rw-r--r--lldb/test/benchmarks/example/TestRepeatedExprs.py7
-rw-r--r--lldb/test/benchmarks/example/main.c6
-rw-r--r--lldb/test/benchmarks/example/main.cpp43
-rw-r--r--lldb/test/lldbbench.py96
5 files changed, 143 insertions, 11 deletions
diff --git a/lldb/test/benchmarks/example/Makefile b/lldb/test/benchmarks/example/Makefile
index 0d70f259501..8a7102e347a 100644
--- a/lldb/test/benchmarks/example/Makefile
+++ b/lldb/test/benchmarks/example/Makefile
@@ -1,5 +1,5 @@
LEVEL = ../../make
-C_SOURCES := main.c
+CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/benchmarks/example/TestRepeatedExprs.py b/lldb/test/benchmarks/example/TestRepeatedExprs.py
index 228e8994e08..c66f1067afc 100644
--- a/lldb/test/benchmarks/example/TestRepeatedExprs.py
+++ b/lldb/test/benchmarks/example/TestRepeatedExprs.py
@@ -23,8 +23,11 @@ class RepeatedExprsCase(BenchBase):
self.run_gdb_repeated_exprs()
def run_lldb_repeated_exprs(self):
- print "running "+self.testMethodName
- print "benchmarks result for "+self.testMethodName
+ for i in range(1000):
+ with self.swatch:
+ print "running "+self.testMethodName
+ print "benchmarks result for "+self.testMethodName
+ print "stopwatch:", str(self.swatch)
def run_gdb_repeated_exprs(self):
print "running "+self.testMethodName
diff --git a/lldb/test/benchmarks/example/main.c b/lldb/test/benchmarks/example/main.c
deleted file mode 100644
index 277aa54a4ee..00000000000
--- a/lldb/test/benchmarks/example/main.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <stdio.h>
-
-int main(int argc, char const *argv[]) {
- printf("Hello world.\n");
- return 0;
-}
diff --git a/lldb/test/benchmarks/example/main.cpp b/lldb/test/benchmarks/example/main.cpp
new file mode 100644
index 00000000000..730a704a7f8
--- /dev/null
+++ b/lldb/test/benchmarks/example/main.cpp
@@ -0,0 +1,43 @@
+#include <stdio.h>
+
+class Point {
+public:
+ int x;
+ int y;
+ Point(int a, int b):
+ x(a),
+ y(b)
+ {}
+};
+
+class Data {
+public:
+ int id;
+ Point point;
+ Data(int i):
+ id(i),
+ point(0, 0)
+ {}
+};
+
+int main(int argc, char const *argv[]) {
+ Data *data[1000];
+ Data **ptr = data;
+ for (int i = 0; i < 1000; ++i) {
+ ptr[i] = new Data(i);
+ ptr[i]->point.x = i;
+ ptr[i]->point.y = i+1;
+ }
+
+ printf("Finished populating data.\n");
+ for (int i = 0; i < 1000; ++i) {
+ bool dump = argc > 1; // Set breakpoint here.
+ // Evaluate a couple of expressions (2*1000 = 2000 exprs):
+ // expr ptr[i]->point.x
+ // expr ptr[i]->point.y
+ if (dump) {
+ printf("data[%d] = %d (%d, %d)\n", i, ptr[i]->id, ptr[i]->point.x, ptr[i]->point.y);
+ }
+ }
+ return 0;
+}
diff --git a/lldb/test/lldbbench.py b/lldb/test/lldbbench.py
index 19dcabc9f07..f094985d8cf 100644
--- a/lldb/test/lldbbench.py
+++ b/lldb/test/lldbbench.py
@@ -1,8 +1,100 @@
-import lldbtest
+import time
from lldbtest import benchmarks_test
+from lldbtest import Base
-class BenchBase(lldbtest.Base):
+class Stopwatch(object):
+ """Stopwatch provides a simple utility to start/stop your stopwatch multiple
+ times. Each start/stop is equal to a lap, with its elapsed time accumulated
+ while measurment is in progress.
+
+ When you're ready to start from scratch for another round of measurements,
+ be sure to call the reset() method.
+
+ For example,
+
+ sw = Stopwatch()
+ for i in range(1000):
+ with sw:
+ # Do some length operations...
+ ...
+ # Get the average time.
+ avg_time = sw.avg()
+
+ # Reset the stopwatch as we are about to perform other kind of operations.
+ sw.reset()
+ ...
+ """
+
+ #############################################################
+ #
+ # Context manager interfaces to support the 'with' statement.
+ #
+ #############################################################
+
+ def __enter__(self):
+ """
+ Context management protocol on entry to the body of the with statement.
+ """
+ return self.start()
+
+ def __exit__(self, type, value, tb):
+ """
+ Context management protocol on exit from the body of the with statement.
+ """
+ self.stop()
+
+ def reset(self):
+ self.__laps__ = 0
+ self.__total_elapsed__ = 0.0
+ self.__start__ = None
+ self.__stop__ = None
+ self.__elapsed__ = 0.0
+
+ def __init__(self):
+ self.reset()
+
+ def start(self):
+ if self.__start__ is None:
+ self.__start__ = time.time()
+ else:
+ raise Exception("start() already called, did you forget to stop() first?")
+ # Return self to facilitate the context manager __enter__ protocol.
+ return self
+
+ def stop(self):
+ if self.__start__ is not None:
+ self.__stop__ = time.time()
+ elapsed = self.__stop__ - self.__start__
+ self.__total_elapsed__ += elapsed
+ self.__laps__ += 1
+ self.__start__ = None # Reset __start__ to be None again.
+ else:
+ raise Exception("stop() called without first start()?")
+
+ def laps(self):
+ """Gets the number of laps. One lap is equal to a start/stop action."""
+ return self.__laps__
+
+ def avg(self):
+ """Equal to total elapsed time divided by the number of laps."""
+ return self.__total_elapsed__ / self.__laps__
+
+ def __str__(self):
+ return "Avg: %f (Laps: %d, Total Elapsed Time: %d)" % (self.avg(),
+ self.__laps__,
+ self.__total_elapsed__)
+
+class BenchBase(Base):
"""
Abstract base class for benchmark tests.
"""
+ def setUp(self):
+ """Fixture for unittest test case setup."""
+ Base.setUp(self)
+ self.swatch = Stopwatch()
+
+ def tearDown(self):
+ """Fixture for unittest test case teardown."""
+ Base.tearDown(self)
+ del self.swatch
OpenPOWER on IntegriCloud