switch to length fn

This commit is contained in:
2026-01-18 10:35:05 -06:00
parent e695810e64
commit 98cb2c3239
31 changed files with 184 additions and 185 deletions

View File

@@ -17,7 +17,7 @@ var sieve = eratosthenes(10000000);
stone(sieve)
var c = 0
for (var i = 0; i < sieve.length; i++)
for (var i = 0; i < length(sieve); i++)
if (sieve.read_logical(i)) c++
log.console(c)

View File

@@ -126,7 +126,7 @@ function benchArrayOps() {
var iterateTime = measureTime(function() {
var sum = 0;
for (var j = 0; j < 1000; j++) {
for (var i = 0; i < arr.length; i++) {
for (var i = 0; i < length(arr); i++) {
sum += arr[i];
}
}

View File

@@ -70,7 +70,7 @@ function offsetMomentum() {
var px = 0;
var py = 0;
var pz = 0;
var size = bodies.length;
var size = length(bodies);
for (var i = 0; i < size; i++) {
var body = bodies[i];
var mass = body.mass;
@@ -86,7 +86,7 @@ function offsetMomentum() {
}
function advance(dt) {
var size = bodies.length;
var size = length(bodies);
for (var i = 0; i < size; i++) {
var bodyi = bodies[i];
@@ -127,7 +127,7 @@ function advance(dt) {
function energy() {
var e = 0;
var size = bodies.length;
var size = length(bodies);
for (var i = 0; i < size; i++) {
var bodyi = bodies[i];

View File

@@ -5,9 +5,9 @@ function A(i,j) {
}
function Au(u,v) {
for (var i=0; i<u.length; ++i) {
for (var i=0; i<length(u); ++i) {
var t = 0;
for (var j=0; j<u.length; ++j)
for (var j=0; j<length(u); ++j)
t += A(i,j) * u[j];
v[i] = t;
@@ -15,9 +15,9 @@ function Au(u,v) {
}
function Atu(u,v) {
for (var i=0; i<u.length; ++i) {
for (var i=0; i<length(u); ++i) {
var t = 0;
for (var j=0; j<u.length; ++j)
for (var j=0; j<length(u); ++j)
t += A(j,i) * u[j];
v[i] = t;

View File

@@ -81,9 +81,9 @@ log.console("===================\n");
// We'll run each benchmark scenario in turn.
for (var bench of benchmarks) {
// We'll measure how long it takes to do 'iterations' *for each test value*
// in bench.data. The total loop count is `bench.iterations * bench.data.length`.
// in bench.data. The total loop count is `bench.iterations * bench.data)`.
// Then we compute an overall encode+decode throughput (ops/s).
var totalIterations = bench.iterations * bench.data.length;
var totalIterations = bench.iterations * bench.data);
// We'll define a function that does a roundTrip for *each* data item in bench.data
// to measure in one loop iteration. Then we multiply by bench.iterations.
@@ -97,7 +97,7 @@ for (var bench of benchmarks) {
var opsPerSec = (totalIterations / elapsedSec).toFixed(1);
log.console(`${bench.name}:`);
log.console(` Iterations: ${bench.iterations} × ${bench.data.length} data items = ${totalIterations}`);
log.console(` Iterations: ${bench.iterations} × ${length(bench.data)} data items = ${totalIterations}`);
log.console(` Elapsed: ${elapsedSec.toFixed(3)} s`);
log.console(` Throughput: ${opsPerSec} encode+decode ops/sec\n`);
}

View File

@@ -13,7 +13,7 @@
//
// Parse command line arguments
if (arg.length != 2) {
if (length(arg) != 2) {
log.console('Usage: cell benchmark_wota_nota_json.ce <LibraryName> <ScenarioName>');
$stop()
}
@@ -32,7 +32,7 @@ def libraries = [
decode: wota.decode,
// wota produces an ArrayBuffer. We'll count `buffer.byteLength` as size.
getSize(encoded) {
return encoded.length;
return length(encoded);
}
},
{
@@ -41,7 +41,7 @@ def libraries = [
decode: nota.decode,
// nota also produces an ArrayBuffer:
getSize(encoded) {
return encoded.length;
return length(encoded);
}
},
{
@@ -52,7 +52,7 @@ def libraries = [
// as a rough "size". Alternatively, you could convert to UTF-8 for
// a more accurate byte size. Here we just use `string.length`.
getSize(encodedStr) {
return encodedStr.length;
return length(encodedStr);
}
}
];
@@ -135,7 +135,7 @@ function runBenchmarkForLibrary(lib, bench) {
var encodeTime = measureTime(() => {
for (var i = 0; i < bench.iterations; i++) {
// For each data item, encode it
for (var j = 0; j < bench.data.length; j++) {
for (var j = 0; j < length(bench.data); j++) {
var e = lib.encode(bench.data[j]);
// store only in the very first iteration, so we can decode them later
// but do not store them every iteration or we blow up memory.
@@ -185,7 +185,7 @@ if (!bench) {
var { encodeTime, decodeTime, totalSize } = runBenchmarkForLibrary(lib, bench);
// Output json for easy parsing by hyperfine or other tools
var totalOps = bench.iterations * bench.data.length;
var totalOps = bench.iterations * length(bench.data);
var result = {
lib: lib_name,
scenario: scenario_name,