forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
74 lines (67 loc) · 1.63 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
var Curry = require("../../lib/js/curry.js");
var Caml_array = require("../../lib/js/caml_array.js");
var Pervasives = require("../../lib/js/pervasives.js");
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions.js");
function map(f, a) {
var f$1 = Curry.__1(f);
var a$1 = a;
var l = a$1.length;
if (l === 0) {
return /* array */[];
} else {
var r = Caml_array.caml_make_vect(l, f$1(a$1[0]));
for(var i = 1 ,i_finish = l - 1 | 0; i <= i_finish; ++i){
r[i] = f$1(a$1[i]);
}
return r;
}
}
function init(l, f) {
var l$1 = l;
var f$1 = Curry.__1(f);
if (l$1 === 0) {
return /* array */[];
} else {
if (l$1 < 0) {
throw [
Caml_builtin_exceptions.invalid_argument,
"Array.init"
];
}
var res = Caml_array.caml_make_vect(l$1, f$1(0));
for(var i = 1 ,i_finish = l$1 - 1 | 0; i <= i_finish; ++i){
res[i] = f$1(i);
}
return res;
}
}
function fold_left(f, x, a) {
var f$1 = Curry.__2(f);
var x$1 = x;
var a$1 = a;
var r = x$1;
for(var i = 0 ,i_finish = a$1.length - 1 | 0; i <= i_finish; ++i){
r = f$1(r, a$1[i]);
}
return r;
}
function f2(param) {
var arr = init(3000000, (function (i) {
return i;
}));
var b = map((function (i) {
return i + i - 1;
}), arr);
var v = fold_left((function (prim, prim$1) {
return prim + prim$1;
}), 0, b);
console.log(Pervasives.string_of_float(v));
return /* () */0;
}
f2(/* () */0);
exports.map = map;
exports.init = init;
exports.fold_left = fold_left;
exports.f2 = f2;
/* Not a pure module */