time-to-botec/squiggle/node_modules/@quri/squiggle-lang/benchmark/Benchmark_Map.bs.js
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

82 lines
2.7 KiB
JavaScript

'use strict';
var Belt_Array = require("@rescript/std/lib/js/belt_Array.js");
var Belt_Range = require("@rescript/std/lib/js/belt_Range.js");
var Belt_MapString = require("@rescript/std/lib/js/belt_MapString.js");
var Belt_HashMapString = require("@rescript/std/lib/js/belt_HashMapString.js");
var Belt_MutableMapString = require("@rescript/std/lib/js/belt_MutableMapString.js");
var Benchmark_Helpers$QuriSquiggleLang = require("./Benchmark_Helpers.bs.js");
var kv = Belt_Array.map(Belt_Array.range(1, 1000), (function (v) {
return [
"key" + String(v),
v
];
}));
function beltMap(param) {
Belt_Range.forEach(1, 10000, (function (param) {
Belt_Array.reduce(kv, undefined, (function (acc, param) {
return Belt_MapString.set(acc, param[0], param[1]);
}));
}));
}
function beltMutableMap(param) {
Belt_Range.forEach(1, 10000, (function (param) {
var m = Belt_MutableMapString.make(undefined);
Belt_Array.reduce(kv, m, (function (acc, param) {
Belt_MutableMapString.set(acc, param[0], param[1]);
return acc;
}));
}));
}
function beltHashMap(param) {
Belt_Range.forEach(1, 10000, (function (param) {
var m = Belt_HashMapString.make(100);
Belt_Array.reduce(kv, m, (function (acc, param) {
Belt_HashMapString.set(acc, param[0], param[1]);
return acc;
}));
}));
}
function jsDict(param) {
Belt_Range.forEach(1, 10000, (function (param) {
var m = {};
Belt_Array.reduce(kv, m, (function (acc, param) {
acc[param[0]] = param[1];
return acc;
}));
}));
}
function jsMap(param) {
Belt_Range.forEach(1, 10000, (function (param) {
var m = new Map();
Belt_Array.reduce(kv, m, (function (acc, param) {
return acc.set(param[0], param[1]);
}));
}));
}
function runAll(param) {
console.log("Filling a map with (\"key{i}\" => \"i\") key-value pairs, size " + (1000).toString() + " (" + (10000).toString() + " iterations)");
Benchmark_Helpers$QuriSquiggleLang.measure("Belt.Map.String", beltMap);
Benchmark_Helpers$QuriSquiggleLang.measure("Belt.MutableMap.String", beltMutableMap);
Benchmark_Helpers$QuriSquiggleLang.measure("Belt.HashMap.String", beltHashMap);
Benchmark_Helpers$QuriSquiggleLang.measure("Js.Dict", jsDict);
Benchmark_Helpers$QuriSquiggleLang.measure("Js.Map", jsMap);
}
var StringMap = {
runAll: runAll
};
var runAll$1 = runAll(undefined);
exports.StringMap = StringMap;
exports.runAll = runAll$1;
/* kv Not a pure module */