93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
var Caml = require("@rescript/std/lib/js/caml.js");
|
|
var $$Array = require("@rescript/std/lib/js/array.js");
|
|
var Belt_Array = require("@rescript/std/lib/js/belt_Array.js");
|
|
var Belt_Range = require("@rescript/std/lib/js/belt_Range.js");
|
|
var Benchmark_Helpers$QuriSquiggleLang = require("./Benchmark_Helpers.bs.js");
|
|
|
|
function beltArray(param) {
|
|
var x = Belt_Array.make(1000, 0);
|
|
Belt_Range.forEach(1, 300000, (function (param) {
|
|
Belt_Array.map(x, (function (v) {
|
|
return v;
|
|
}));
|
|
}));
|
|
}
|
|
|
|
function jsArray2(param) {
|
|
var x = Belt_Array.make(1000, 0);
|
|
Belt_Range.forEach(1, 300000, (function (param) {
|
|
x.map(function (v) {
|
|
return v;
|
|
});
|
|
}));
|
|
}
|
|
|
|
function ocamlArray(param) {
|
|
var x = Belt_Array.make(1000, 0);
|
|
Belt_Range.forEach(1, 300000, (function (param) {
|
|
$$Array.map((function (v) {
|
|
return v;
|
|
}), x);
|
|
}));
|
|
}
|
|
|
|
function runAll(param) {
|
|
console.log("Mapping identity function over arrays of size " + (1000).toString() + " (" + (300000).toString() + " iterations)");
|
|
Benchmark_Helpers$QuriSquiggleLang.measure("Belt.Array.map", beltArray);
|
|
Benchmark_Helpers$QuriSquiggleLang.measure("Js.Array2.map", jsArray2);
|
|
Benchmark_Helpers$QuriSquiggleLang.measure("Array.map", ocamlArray);
|
|
}
|
|
|
|
var $$Map = {
|
|
runAll: runAll
|
|
};
|
|
|
|
function jsArray2$1(param) {
|
|
var x = Belt_Array.make(1000, 0);
|
|
var compare = function (a, b) {
|
|
if (a < b) {
|
|
return -1;
|
|
} else {
|
|
return 1;
|
|
}
|
|
};
|
|
Belt_Range.forEach(1, 30000, (function (param) {
|
|
x.sort(compare);
|
|
}));
|
|
}
|
|
|
|
function jsArray2withOcamlCompare(param) {
|
|
var x = Belt_Array.make(1000, 0);
|
|
Belt_Range.forEach(1, 30000, (function (param) {
|
|
x.sort(Caml.float_compare);
|
|
}));
|
|
}
|
|
|
|
function ocamlArray$1(param) {
|
|
var x = Belt_Array.make(1000, 0);
|
|
Belt_Range.forEach(1, 30000, (function (param) {
|
|
$$Array.fast_sort(Caml.float_compare, x);
|
|
}));
|
|
}
|
|
|
|
function runAll$1(param) {
|
|
console.log("Sorting arrays of size " + (1000).toString() + " (" + (30000).toString() + " iterations)");
|
|
Benchmark_Helpers$QuriSquiggleLang.measure("Js.Array2.sort", jsArray2$1);
|
|
Benchmark_Helpers$QuriSquiggleLang.measure("Js.Array2.sort with Ocaml compare", jsArray2withOcamlCompare);
|
|
Benchmark_Helpers$QuriSquiggleLang.measure("Array.fast_sort", ocamlArray$1);
|
|
}
|
|
|
|
var Sort = {
|
|
runAll: runAll$1
|
|
};
|
|
|
|
runAll(undefined);
|
|
|
|
runAll$1(undefined);
|
|
|
|
exports.$$Map = $$Map;
|
|
exports.Sort = Sort;
|
|
/* Not a pure module */
|