diff --git a/experiments/fact/foo.html b/experiments/fact/foo.html index 93c8b96..3e26e07 100644 --- a/experiments/fact/foo.html +++ b/experiments/fact/foo.html @@ -8,19 +8,19 @@ var f = MACHINE.env.globalBindings.factorial.adaptToJs(); var startTime; +var N = 1000000; + startTime = new Date(); -f([10000000], function(v) { console.log(v, new Date() - startTime); }); +f([N], function(v) { console.log("switch", v, new Date() - startTime); }); var mul = function(x, y) { return x * y; } startTime = new Date(); -var acc; -for (i = 1; i < 10000000; i++) { - acc = mul(acc * i); +var acc = 1; +for (var i = 1; i <= N; i++) { + acc = mul(acc, i); } -console.log(acc, new Date() - startTime); - - +console.log("loops", acc, new Date() - startTime);
diff --git a/experiments/fact/foo2.html b/experiments/fact/foo2.html index 57d85ac..4c3e61c 100644 --- a/experiments/fact/foo2.html +++ b/experiments/fact/foo2.html @@ -8,17 +8,19 @@ var f = MACHINE.env.globalBindings.factorial.adaptToJs(); var startTime; +var N = 1000000; + startTime = new Date(); -f([10], function(v) { console.log(v, new Date() - startTime); }); +f([N], function(v) { console.log("switch", v, new Date() - startTime); }); -//var mul = function(x, y) { return x * y; } -//startTime = new Date(); -//var acc; -//for (i = 1; i < 10000000; i++) { -// acc = mul(acc * i); -//} -//console.log(acc, new Date() - startTime); +var mul = function(x, y) { return x * y; } +startTime = new Date(); +var acc = 1; +for (var i = 1; i <= N; i++) { + acc = mul(acc, i); +} +console.log("loops", acc, new Date() - startTime); diff --git a/experiments/fact/foo2.js b/experiments/fact/foo2.js index 7cb4a60..4093423 100644 --- a/experiments/fact/foo2.js +++ b/experiments/fact/foo2.js @@ -108,11 +108,6 @@ var invoke = function(k) { var program = function() { while(true) { - if (typeof(MACHINE.label) === 'function') { - MACHINE.label(); - return; - } - switch(MACHINE.label) { case 1: @@ -243,7 +238,8 @@ var program = function() { default: - throw new Error("impossible situation"); + return MACHINE.label(); + return; } }