-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffi-bench.js
70 lines (58 loc) · 1.9 KB
/
ffi-bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { createRequire } from "node:module"
import { Compiler } from './lib/tcc.js'
import { bind, assert, dlsym, dlopen, RTLD_NOW, RTLD_LOCAL } from './lib/ffast.js'
import { Bench } from './lib/bench.js'
const handle = assert(dlopen('./build/Release/noop.node', RTLD_NOW | RTLD_LOCAL))
const sym = assert(dlsym(handle, 'noop'))
//const noop = createRequire(import.meta.url)('./build/Release/noop.node')
const compiler = new Compiler()
compiler.compile(`
void noop () {
}
`)
const noop_fast_ffi = bind(sym, 'void', [])
const noop_slow_ffi = bind(sym, 'void', [], true)
const noop_fast_ffi_tcc = bind(compiler.symbol('noop'), 'void', [])
const noop_slow_ffi_tcc = bind(compiler.symbol('noop'), 'void', [], true)
//const { noop_fast, noop_slow } = noop
const bench = new Bench()
while (1) {
/*
for (let j = 0; j < 5; j++) {
const runs = 300000000
bench.start('noop_fast')
for (let i = 0; i < runs; i++) assert(noop_fast() === undefined)
bench.end(runs)
}
for (let j = 0; j < 5; j++) {
const runs = 100000000
bench.start('noop_slow')
for (let i = 0; i < runs; i++) assert(noop_slow() === undefined)
bench.end(runs)
}
*/
for (let j = 0; j < 5; j++) {
const runs = 300000000
bench.start('noop_fast_ffi')
for (let i = 0; i < runs; i++) assert(noop_fast_ffi() === undefined)
bench.end(runs)
}
for (let j = 0; j < 5; j++) {
const runs = 100000000
bench.start('noop_slow_ffi')
for (let i = 0; i < runs; i++) assert(noop_slow_ffi() === undefined)
bench.end(runs)
}
for (let j = 0; j < 5; j++) {
const runs = 300000000
bench.start('noop_fast_ffi_tcc')
for (let i = 0; i < runs; i++) assert(noop_fast_ffi_tcc() === undefined)
bench.end(runs)
}
for (let j = 0; j < 5; j++) {
const runs = 100000000
bench.start('noop_slow_ffi_tcc')
for (let i = 0; i < runs; i++) assert(noop_slow_ffi_tcc() === undefined)
bench.end(runs)
}
}