1Elm.Native.Benchmark = {};
2Elm.Native.Benchmark.make = function(localRuntime) {
4 localRuntime.Native = localRuntime.Native || {};
5 localRuntime.Native.Benchmark = localRuntime.Native.Benchmark || {};
6 if (localRuntime.Native.Benchmark.values)
8 return localRuntime.Native.Benchmark.values;
11 var List = Elm.Native.List.make(localRuntime);
12 var Task = Elm.Native.Task.make(localRuntime);
13 var Signal = Elm.Signal.make(localRuntime);
14 var Utils = Elm.Native.Utils.make(localRuntime);
16 //Nothing special happens here, but we need to use it as a Native function
17 //So that we can accept thunks of any type
18 function makeBenchmark(name, thunk)
20 return {name : name, thunk : thunk};
23 //Generate the task for running a benchmark suite
24 //Possibly updating a given mailbox with a string describing
25 //Our progress of running the benchmarks so far
26 function runWithProgress(maybeTaskFn, inSuite)
29 return Task.asyncFunction(function(callback) {
30 var bjsSuite = new Benchmark.Suite;
40 benchArray = List.toArray(inSuite._1);
42 case "SingleBenchmark":
43 benchArray = [inSuite._0 ];
47 numToRun = benchArray.length;
48 Task.perform(maybeTaskFn("Running benchmark 1 of " + numToRun));
50 //Initialize each benchmark in the suite
51 for (i = 0; i < benchArray.length; i++)
53 var ourThunk = function (){
54 //Run the thing we're timing, then mark the asynch benchmark as done
55 benchArray[i].thunk();
58 bjsSuite.add(benchArray[i].name, benchArray[i].thunk );
61 //Every time a benchmark finishes, we store its results
62 //and update our progress string
63 bjsSuite.on('cycle', function(event) {
66 { name : event.target.options.name
67 , hz : event.target.hz
68 , marginOfError : event.target.stats.moe
69 , moePercent : event.target.stats.rme
72 finalString += String(event.target) + "\n";
77 + "\nLast result: " + String(event.target);
78 Task.perform(maybeTaskFn(intermedString));
79 //retString += String(event.target) + "\n";
82 //When the last benchmark finishes, we show all results collected
83 bjsSuite.on('complete', function(event) {
84 Task.perform(maybeTaskFn("Final results:\n\n" + finalString) );
85 return callback(Task.succeed(Utils.Tuple2(finalString, List.fromArray(retData))));
88 //Finally: actually run the suite
90 Task.asyncFunction(function(otherCallback){
91 bjsSuite.run({ 'async': true });
96 return localRuntime.Native.Benchmark.values = {
97 makeBenchmark: F2(makeBenchmark),
98 runWithProgress: F2(runWithProgress)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list