8000 fastcalls by telamon · Pull Request #2 · holepunchto/simdle-native · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fastcalls #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch)
find_package(cmake-napi REQUIRED PATHS node_modules/cmake-napi)

project(simdle_native C)
project(simdle_native C CXX)

bare_target(target)

Expand All @@ -13,19 +13,21 @@ if(target MATCHES "win32")
endif()

fetch_package("github:holepunchto/libsimdle#014ad4e")
fetch_package("github:holepunchto/libjstl#2188770")

add_bare_module(simdle_native_bare)

target_sources(
${simdle_native_bare}
PRIVATE
binding.c
binding.cc
)

target_link_libraries(
${simdle_native_bare}
PRIVATE
$<TARGET_OBJECTS:simdle>
jstl
PUBLIC
simdle
)
Expand All @@ -35,13 +37,22 @@ add_napi_module(simdle_native_node)
target_sources(
${simdle_native_node}
PRIVATE
binding.c
binding.cc
)

target_link_libraries(
${simdle_native_node}
PRIVATE
$<TARGET_OBJECTS:simdle>
PUBLIC
jstl
simdle
)

resolve_node_module(bare-compat-napi compat)

target_include_directories(
${simdle_native_node}
PRIVATE
"${compat}/include"
)
108 changes: 108 additions & 0 deletions bench.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { test } from 'brittle'
import { cnt, clz } from './index.js'
import {
cnt as jscnt,
clz as jsclz
} from 'simdle-universal/fallback.js'

test('cnt-16', t => {
let nativeOps, jsOps
const N = 2e7

const result = new Uint16Array(8)
const input = Uint16Array.of(
0b0000000000000000, 0b0000000000000001,
0b0000000000000011, 0b0000000000000111,
0b0000000000001111, 0b0000000000011111,
0b0000000000111111, 0b0000000001111111
)

t.test('native', t => {
const measure = benchmark(t.comment)

for (let i = 0; i < N; i++) {
cnt(input, result)
measure(1)
}
nativeOps = measure(-1)
})

t.test('js', t => {
const measure = benchmark(t.comment)
for (let i = 0; i < N; i++) {
jscnt(input, result)
measure(1)
}
jsOps = measure(-1)
})

t.test('comparison', t => {
const r = (nativeOps / jsOps) - 1
t.comment(`native ${nativeOps.toExponential(2)} vs. js ${jsOps.toExponential(2)}; ${(r * 100).toFixed(2)}%`)
})
})

test('clz-32', t => {
let nativeOps, jsOps
const N = 1e6

const width = 256
const result = new Uint32Array(width)
const input = Uint32Array.of(
...Array.from(new Array(width)).map((_, i) => 1 * (2 ** (i % 32)))
)

t.test('native', t => {
const measure = benchmark(t.comment)

for (let i = 0; i < N; i++) {
clz(input, result)
measure(1)
}

nativeOps = measure(-1)
})

t.test('js', t => {
const measure = benchmark(t.comment)

for (let i = 0; i < N; i++) {
jsclz(input, result)
measure(1)
}

jsOps = measure(-1)
})

t.test('comparison', t => {
const r = (nativeOps / jsOps) - 1
t.comment(`native ${nativeOps.toExponential(2)} vs. js ${jsOps.toExponential(2)}; ${(r * 100).toFixed(2)}%`)
})
})

function benchmark (log = console.log, interval = 2000) {
let prev
const start = prev = Date.now()
let n = 0
let total = n

return function measure (qty = 1) {
const now = Date.now()
const delta = now - prev

if (qty > 0) {
n += qty
total += qty
}

if ((interval && interval < delta) || qty < 0) {
const ops = (n / delta) * 1000
const runtime = now - start
const avg = (total / runtime) * 1000
log('ops', ops.toExponential(2), 'avg', Math.round(avg), 'total', total, 'runtime', runtime)
prev = now
n = 0
return ops
}
}
}
Loading
0