MCPcopy Create free account
hub / github.com/apache/fory / benchmark

Function benchmark

benchmarks/javascript/benchmark.js:960–982  ·  view source on GitHub ↗
(fn, minDurationSeconds)

Source from the content-addressed store, hash-verified

958}
959
960function benchmark(fn, minDurationSeconds) {
961 fn();
962 let batchSize = 1;
963 while (batchSize < 1_000_000) {
964 const elapsed = measureBatch(fn, batchSize);
965 if (elapsed >= 10_000_000n) {
966 break;
967 }
968 batchSize *= 2;
969 }
970
971 const targetNs = BigInt(Math.floor(minDurationSeconds * 1e9));
972 let totalElapsed = 0n;
973 let totalIterations = 0;
974
975 while (totalElapsed < targetNs) {
976 const elapsed = measureBatch(fn, batchSize);
977 totalElapsed += elapsed;
978 totalIterations += batchSize;
979 }
980
981 return Number(totalElapsed) / totalIterations;
982}
983
984function buildResults(datasets, options) {
985 const benchmarks = [];

Callers 1

buildResultsFunction · 0.85

Calls 3

measureBatchFunction · 0.85
NumberClass · 0.85
floorMethod · 0.80

Tested by

no test coverage detected