diff --git a/benchmarks/rbtree_bench.js b/benchmarks/rbtree_bench.js index dda9889..8ef59a6 100644 --- a/benchmarks/rbtree_bench.js +++ b/benchmarks/rbtree_bench.js @@ -1,7 +1,8 @@ import createTree from "functional-red-black-tree"; +import { emptyTrie, insert } from "../lib/util/trie.js"; function benchmark(N) { - // fastest + // in-place update of native Map: fastest function map() { let t = new Map(); const startTime = Date.now(); @@ -11,10 +12,10 @@ function benchmark(N) { const endTime = Date.now(); return endTime - startTime; } - const durInPlace = map(); + const durInPlace = (N <= 5000000) ? map() : "(skip)"; console.log("in-place:", durInPlace, "ms"); - // slower by constant factor + // purely functional red-black tree: slower by constant factor function fun() { let t = createTree(); const startTime = Date.now(); @@ -25,25 +26,55 @@ function benchmark(N) { return endTime - startTime; } const durFunc = fun(); - console.log("functional:", durFunc, "ms"); + console.log("functional red-black:", durFunc, "ms"); - // a bit slower still + // purely functional red-black tree (no garbage collection): a bit slower still function funNoGC() { - const old = new Array(N); + const trees = new Array(N); let t = createTree(); const startTime = Date.now(); for (let i=0; i