This commit is contained in:
2026-02-20 15:33:46 -06:00
parent 11fb213a74
commit 5af76bce9b
40 changed files with 284 additions and 314 deletions

View File

@@ -11,8 +11,8 @@ var fd = use('fd')
var shop = use('internal/shop')
if (length(args) < 1) {
print('usage: cell --dev run_native <module>')
print(' e.g. cell --dev run_native num_torture')
log.compile('usage: cell --dev run_native <module>')
log.compile(' e.g. cell --dev run_native num_torture')
return
}
@@ -28,52 +28,52 @@ if (length(args) > 1) {
}
// --- Interpreted run ---
print('--- interpreted ---')
log.compile('--- interpreted ---')
var t1 = os.now()
var mod_interp = use(name)
var t2 = os.now()
var result_interp = null
if (is_function(mod_interp)) {
print('module returns a function, calling with ' + text(test_arg))
log.compile('module returns a function, calling with ' + text(test_arg))
t1 = os.now()
result_interp = mod_interp(test_arg)
t2 = os.now()
}
result_interp = result_interp != null ? result_interp : mod_interp
var ms_interp = (t2 - t1) / 1000000
print('result: ' + text(result_interp))
print('time: ' + text(ms_interp) + ' ms')
log.compile('result: ' + text(result_interp))
log.compile('time: ' + text(ms_interp) + ' ms')
// --- Native run ---
// Resolve to .cm path for shop.use_native()
var mod_path = name + '.cm'
if (!fd.is_file(mod_path)) {
print('\nno ' + mod_path + ' found')
log.error('\nno ' + mod_path + ' found')
return
}
print('\n--- native ---')
log.compile('\n--- native ---')
var t3 = os.now()
var mod_native = shop.use_native(mod_path)
var t4 = os.now()
var result_native = null
if (is_function(mod_native)) {
print('module returns a function, calling with ' + text(test_arg))
log.compile('module returns a function, calling with ' + text(test_arg))
t3 = os.now()
result_native = mod_native(test_arg)
t4 = os.now()
}
result_native = result_native != null ? result_native : mod_native
var ms_native = (t4 - t3) / 1000000
print('result: ' + text(result_native))
print('time: ' + text(ms_native) + ' ms')
log.compile('result: ' + text(result_native))
log.compile('time: ' + text(ms_native) + ' ms')
// --- Comparison ---
print('\n--- comparison ---')
log.compile('\n--- comparison ---')
var match = result_interp == result_native
var speedup = 0
print('match: ' + text(match))
log.compile('match: ' + text(match))
if (ms_native > 0) {
speedup = ms_interp / ms_native
print('speedup: ' + text(speedup) + 'x')
log.compile('speedup: ' + text(speedup) + 'x')
}