remove typeof'
This commit is contained in:
29
bench.ce
29
bench.ce
@@ -203,7 +203,7 @@ function calibrate_batch_size(bench_fn, is_batch) {
|
||||
// Find a batch size that takes at least MIN_SAMPLE_NS
|
||||
while (n < MAX_BATCH_SIZE) {
|
||||
// Ensure n is a valid number before calling
|
||||
if (typeof n != 'number' || n < 1) {
|
||||
if (!is_number(n) || n < 1) {
|
||||
n = 1
|
||||
break
|
||||
}
|
||||
@@ -217,7 +217,7 @@ function calibrate_batch_size(bench_fn, is_batch) {
|
||||
// Double the batch size
|
||||
var new_n = n * 2
|
||||
// Check if multiplication produced a valid number
|
||||
if (typeof new_n != 'number' || new_n > MAX_BATCH_SIZE) {
|
||||
if (!is_number(new_n) || new_n > MAX_BATCH_SIZE) {
|
||||
n = MAX_BATCH_SIZE
|
||||
break
|
||||
}
|
||||
@@ -225,12 +225,12 @@ function calibrate_batch_size(bench_fn, is_batch) {
|
||||
}
|
||||
|
||||
// Adjust to target sample duration
|
||||
if (dt > 0 && dt < TARGET_SAMPLE_NS && typeof n == 'number' && typeof dt == 'number') {
|
||||
if (dt > 0 && dt < TARGET_SAMPLE_NS && is_number(n) && is_number(dt)) {
|
||||
var calc = n * TARGET_SAMPLE_NS / dt
|
||||
if (typeof calc == 'number' && calc > 0) {
|
||||
if (is_number(calc) && calc > 0) {
|
||||
var target_n = number.floor(calc)
|
||||
// Check if floor returned a valid number
|
||||
if (typeof target_n == 'number' && target_n > 0) {
|
||||
if (is_number(target_n) && target_n > 0) {
|
||||
if (target_n > MAX_BATCH_SIZE) target_n = MAX_BATCH_SIZE
|
||||
if (target_n < MIN_BATCH_SIZE) target_n = MIN_BATCH_SIZE
|
||||
n = target_n
|
||||
@@ -239,7 +239,7 @@ function calibrate_batch_size(bench_fn, is_batch) {
|
||||
}
|
||||
|
||||
// Safety check - ensure we always return a valid batch size
|
||||
if (typeof n != 'number' || n < 1) {
|
||||
if (!is_number(n) || n < 1) {
|
||||
n = 1
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ function run_single_bench(bench_fn, bench_name) {
|
||||
// 1. Object with { setup, run, teardown } - structured format
|
||||
// 2. Function that accepts (n) - batch format
|
||||
// 3. Function that accepts () - legacy format
|
||||
var is_structured = typeof bench_fn == 'object' && bench_fn.run
|
||||
var is_structured = is_object(bench_fn) && bench_fn.run
|
||||
var is_batch = false
|
||||
var batch_size = 1
|
||||
var setup_fn = null
|
||||
@@ -285,7 +285,7 @@ function run_single_bench(bench_fn, bench_name) {
|
||||
batch_size = calibrate_batch_size(calibrate_fn, is_batch)
|
||||
|
||||
// Safety check for structured benchmarks
|
||||
if (typeof batch_size != 'number' || batch_size < 1) {
|
||||
if (!is_number(batch_size) || batch_size < 1) {
|
||||
batch_size = 1
|
||||
}
|
||||
} else {
|
||||
@@ -307,8 +307,9 @@ function run_single_bench(bench_fn, bench_name) {
|
||||
// Warmup phase
|
||||
for (var i = 0; i < WARMUP_BATCHES; i++) {
|
||||
// Ensure batch_size is valid before warmup
|
||||
if (typeof batch_size != 'number' || batch_size < 1) {
|
||||
log.console(`WARNING: batch_size became ${typeof batch_size} = ${batch_size}, resetting to 1`)
|
||||
if (!is_number(batch_size) || batch_size < 1) {
|
||||
var type_str = is_null(batch_size) ? 'null' : is_number(batch_size) ? 'number' : is_text(batch_size) ? 'text' : is_object(batch_size) ? 'object' : is_array(batch_size) ? 'array' : is_function(batch_size) ? 'function' : is_logical(batch_size) ? 'logical' : 'unknown'
|
||||
log.console(`WARNING: batch_size became ${type_str} = ${batch_size}, resetting to 1`)
|
||||
batch_size = 1
|
||||
}
|
||||
|
||||
@@ -332,7 +333,7 @@ function run_single_bench(bench_fn, bench_name) {
|
||||
// Measurement phase - collect SAMPLES timing samples
|
||||
for (var i = 0; i < SAMPLES; i++) {
|
||||
// Double-check batch_size is valid (should never happen, but defensive)
|
||||
if (typeof batch_size != 'number' || batch_size < 1) {
|
||||
if (!is_number(batch_size) || batch_size < 1) {
|
||||
batch_size = 1
|
||||
}
|
||||
|
||||
@@ -439,11 +440,11 @@ function run_benchmarks(package_name, specific_bench) {
|
||||
bench_mod = shop.use(mod_path, use_pkg)
|
||||
|
||||
var benches = []
|
||||
if (typeof bench_mod == 'function') {
|
||||
if (is_function(bench_mod)) {
|
||||
benches.push({name: 'main', fn: bench_mod})
|
||||
} else if (typeof bench_mod == 'object') {
|
||||
} else if (is_object(bench_mod)) {
|
||||
for (var k in bench_mod) {
|
||||
if (typeof bench_mod[k] == 'function') {
|
||||
if (is_function(bench_mod[k])) {
|
||||
benches.push({name: k, fn: bench_mod[k]})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user