Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Benchmark] First pass rewrite of benchmark code

  • Loading branch information...
commit 446fe232aec0eb509b6633f8fcc9c4ed4702e897 1 parent 49ffe64
@Whiteknight authored
View
15 src/unstable/benchmark/Includes.winxed
@@ -0,0 +1,15 @@
+// includes for Benchmark
+
+inline percent_of_base(float base, float t)
+{
+ return (t / base) * 100;
+}
+
+inline percent_difference(float base, float t)
+{
+ float diff = t - base;
+ return (diff / base) * 100;
+}
+
+const string FMT_RAW_TIME = "%f";
+const string FMT_PERCENTAGE = "%%%f";
View
133 src/unstable/benchmark/Result.winxed
@@ -1,62 +1,73 @@
-namespace Rosella { namespace Benchmark
+class Rosella.Benchmark.Result
{
- class Result
- {
- var time;
- var percent;
- var percent_diff;
- var data;
-
- function Result(float time, float percent, float percent_diff, var data)
- {
- self.time = time;
- self.percent = percent;
- self.percent_diff = percent_diff;
- self.data = data;
- }
-
- function set_base_time(float base)
- {
- using Rosella.Benchmark.percent_of_base;
- using Rosella.Benchmark.percent_difference;
-
- self.percent = percent_of_base(base, self.time);
- self.percent_diff = percent_difference(base, self.time);
- }
-
- function time()
- {
- return self.time;
- }
-
- function percent()
- {
- return self.percent;
- }
-
- function percent_diff()
- {
- return self.percent_diff;
- }
-
- function data()
- {
- return self.data;
- }
-
- function get_string[vtable]()
- {
- if (self.percent_diff == null || float(self.percent_diff) == 0.0 || float(self.percent_diff) == 100.0)
- return sprintf("%fs - %%%f", [self.time, self.percent]);
- string sign = "+";
- float diff = self.percent_diff;
- if (diff < 0.0) {
- sign = "-";
- diff = abs_f(diff);
- }
- return sprintf("%fs - %%%f (%s%%%f compared to base)",
- [self.time, self.percent, sign, diff]
- );
- }
- }
-}}
+ var benchmark;
+ var name;
+ var action;
+ var starttime;
+ var endtime;
+
+
+ function Result(var benchmark, string name, var action, float starttime, float endtime)
+ {
+ self.benchmark = benchmark;
+ self.name = name;
+ self.action = action;
+ self.starttime = starttime;
+ self.endtime = endtime;
+ }
+
+ function name()
+ {
+ return self.name;
+ }
+
+ function action()
+ {
+ return self.action;
+ }
+
+ function start_time()
+ {
+ return self.starttime;
+ }
+
+ function end_time()
+ {
+ return self.endtime;
+ }
+
+ function total_time()
+ {
+ return float(self.endtime) - float(self.starttime);
+ }
+
+ function total_difference(var base = null)
+ {
+ if (base == null)
+ base = self.benchmark.control_result;
+ return self.total_time() - base.total_time();
+ }
+
+ function percent_of_base(var base = null)
+ {
+ if (base == null)
+ base = self.benchmark.control_result;
+ float time = self.total_time();
+ float base_time = base.total_time();
+ return percent_of_base(base_time, time);
+ }
+
+ function percent_difference(var base = null)
+ {
+ if (base == null)
+ base = self.benchmark.control_result;
+ float time = self.total_time();
+ float base_time = base.total_time();
+ return percent_difference(base_time, time);
+ }
+
+ function sign_compared_to_base()
+ {
+ // TODO: Return "+" if higher than base, "-" otherwise
+ }
+}
View
27 src/unstable/benchmark/ResultFormatter.winxed
@@ -0,0 +1,27 @@
+class Rosella.Benchmark.ResultFormatter : Rosella.StringFormatter
+{
+ function ResultFormatter() { }
+
+ function format(var obj, string f)
+ {
+ if (contains_substr(f, "{name}")) f = f.replace("{name}", obj.name()));
+ if (contains_substr(f, "{time}")) f = f.replace("{time}", format_string(FMT_RAW_TIME, obj.total_time()));
+ if (contains_substr(f, "{start}")) f = f.replace("{start}", format_string(FMT_RAW_TIME, obj.start_time()));
+ if (contains_substr(f, "{end}")) f = f.replace("{end}", format_string(FMT_RAW_TIME, obj.end_time()));
+ if (contains_substr(f, "{%base}")) f = f.replace("{%base}", format_string(FMT_PERCENTAGE, obj.precent_of_base()));
+ if (contains_substr(f, "{%diff}")) f = f.replace("{%diff}", format_string(FMT_PERCENTAGE, obj.percent_difference()));
+ if (contains_substr(f, "{sign}")) f = f.replace("{sign}", obj.sign_compared_to_base()));
+ return f;
+ }
+
+ // Create a string from the object using a default formatting rule
+ function format_default(var obj)
+ {
+ return self.format(obj, "{name}: {time}s - {%base} ({sign}{%diff} of base)");
+ }
+
+ function format_default_base(var obj)
+ {
+ return self.format(obj, "{name}: {time}s");
+ }
+}
View
18 src/unstable/benchmark/ResultView.winxed
@@ -0,0 +1,18 @@
+class Rosella.Benchmark.ResultView
+{
+ var handle;
+
+ function ResultView(var handle = getstdout()) { self.handle = handle; }
+
+ function display_result(string name, var result)
+ {
+ string s = Rosella.Benchmark.default_result_formatter().format_default(result);
+ self.handle.print(s + "\n");
+ }
+
+ function display_all(var results)
+ {
+ for (string r_name in results)
+ self.display_result(r_name, results[r_name]);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.