Files
cell/benchmarks/nota.ce
2026-02-26 08:13:18 -06:00

76 lines
2.1 KiB
Plaintext

var nota = use('internal/nota')
var os = use('internal/os')
var io = use('fd')
var json = use('json')
var ll = io.slurp('benchmarks/nota.json')
var newarr = []
var accstr = ""
var i = 0
var start = null
var jll = null
var jsonStr = null
var nll = null
var oll = null
for (i = 0; i < 10000; i++) {
accstr += i;
newarr[] = text(i)
}
var jsonDecodeTimes = [];
var jsonEncodeTimes = [];
var notaEncodeTimes = [];
var notaDecodeTimes = [];
var notaSizes = [];
for (i = 0; i < 100; i++) {
start = os.now();
jll = json.decode(ll);
jsonDecodeTimes[] = (os.now() - start) * 1000;
start = os.now();
jsonStr = JSON.stringify(jll);
jsonEncodeTimes[] = (os.now() - start) * 1000;
start = os.now();
nll = nota.encode(jll);
notaEncodeTimes[] = (os.now() - start) * 1000;
start = os.now();
oll = nota.decode(nll);
notaDecodeTimes[] = (os.now() - start) * 1000;
}
function getStats(arr) {
return {
avg: reduce(arr, (a,b) => a+b, 0) / length(arr),
min: reduce(arr, min),
max: reduce(arr, max)
};
}
log.console("\n== Performance Test Results (100 iterations) ==");
log.console("\nJSON Decoding (ms):");
def jsonDecStats = getStats(jsonDecodeTimes);
log.console(`Average: ${jsonDecStats.avg.toFixed(2)} ms`);
log.console(`Min: ${jsonDecStats.min.toFixed(2)} ms`);
log.console(`Max: ${jsonDecStats.max.toFixed(2)} ms`);
log.console("\nJSON Encoding (ms):");
def jsonEncStats = getStats(jsonEncodeTimes);
log.console(`Average: ${jsonEncStats.avg.toFixed(2)} ms`);
log.console(`Min: ${jsonEncStats.min.toFixed(2)} ms`);
log.console(`Max: ${jsonEncStats.max.toFixed(2)} ms`);
log.console("\nNOTA Encoding (ms):");
def notaEncStats = getStats(notaEncodeTimes);
log.console(`Average: ${notaEncStats.avg.toFixed(2)} ms`);
log.console(`Min: ${notaEncStats.min.toFixed(2)} ms`);
log.console(`Max: ${notaEncStats.max.toFixed(2)} ms`);
log.console("\nNOTA Decoding (ms):");
def notaDecStats = getStats(notaDecodeTimes);
log.console(`Average: ${notaDecStats.avg.toFixed(2)} ms`);
log.console(`Min: ${notaDecStats.min.toFixed(2)} ms`);
log.console(`Max: ${notaDecStats.max.toFixed(2)} ms`);