Skip to content

Commit

Permalink
Add benchmark (#4)
Browse files Browse the repository at this point in the history
* Add benchmark

* Add json parse/stringify

* Add float benchmark
  • Loading branch information
XuJiandong authored Oct 17, 2023
1 parent 3932755 commit 10ce40e
Show file tree
Hide file tree
Showing 6 changed files with 733 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
run: make install
- name: Tests
run: make test
- name: Benchmark
run: make benchmark

macos:
runs-on: macos-latest
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ test:
make -f tests/basic/Makefile
cd tests/ckb_js_tests && make all

benchmark:
make -f tests/benchmark/Makefile

clean:
rm -f build/*.o
rm -f build/ckb-js-vm
Expand Down
9 changes: 7 additions & 2 deletions tests/basic/test_float.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ function assert(actual, expected, message) {
if (arguments.length == 1)
expected = true;

if (actual == expected)
if (actual === expected)
return;

if (actual !== null && expected !== null
&& typeof actual == 'object' && typeof expected == 'object'
&& actual.toString() === expected.toString())
return;

throw Error("assertion failed: got |" + actual + "|" +
Expand All @@ -14,7 +19,7 @@ function assert(actual, expected, message) {

function test_to_string() {
assert(1.1.toString(), "1.1")
assert(-1.1.toString(), "-1.100000")
assert((-1.1).toString(), "-1.1")
assert(3.14159265354.toString(), "3.1415926540000000")
}

Expand Down
23 changes: 23 additions & 0 deletions tests/benchmark/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

CKB-DEBUGGER := ckb-debugger
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_PATH := $(ROOT_DIR)/../../build/ckb-js-vm

MAX-CYCLES ?= 2000000000
TEST-FILE ?=

define run
$(CKB-DEBUGGER) --max-cycles $(MAX-CYCLES) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -r 2>&1 | fgrep 'Run result: 0'
endef

define debug
$(CKB-DEBUGGER) --max-cycles $(MAX-CYCLES) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -r
endef

define compile-run
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | awk '/Run result: 0/{exit} {print}' | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/../../build/$(1).bc --bin $(BIN_PATH) -- -r | tee $(ROOT_DIR)/benchmark.txt
endef

all:
$(call compile-run,benchmark.js)
Loading

0 comments on commit 10ce40e

Please sign in to comment.