diff --git a/Makefile b/Makefile index a64c3e5..b8dd7c1 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,14 @@ tests: $(WASM_FILES) sieve-vanilla: $(WASM_FILES) $(PARCEL) --no-hmr -o dist/sieve-vanilla.html tests/benchmarks/sieve-vanilla/index.html +.PHONY: benchmark-sieve +benchmark-sieve: $(WASM_FILES) + $(PARCEL) build -o dist/benchmark-sieve.html tests/benchmarks/sieve/index.html + +.PHONY: benchmark-sieve-dev +benchmark-sieve-dev: $(WASM_FILES) + $(PARCEL) --no-hmr tests/benchmarks/sieve/index.html + wasm: $(WASM_FILES) src/tools/quadruple.wasm.hex dist/waforth.wasm: src/waforth.wat dist diff --git a/src/shell/index.js b/src/shell/index.js index 1752547..53fc006 100644 --- a/src/shell/index.js +++ b/src/shell/index.js @@ -2,33 +2,11 @@ import "whatwg-fetch"; import "promise-polyfill/src/polyfill"; import $ from "jquery"; import WAForth from "./WAForth"; +import sieve from "./sieve"; window.jQuery = $; require("jq-console"); -// Copied from https://rosettacode.org/wiki/Sieve_of_Eratosthenes#Forth -const sieve = ` - : prime? HERE + C@ 0= ; - : composite! HERE + 1 SWAP C! ; - - : sieve - HERE OVER ERASE - 2 - BEGIN - 2DUP DUP * > - WHILE - DUP prime? IF - 2DUP DUP * DO - I composite! - DUP +LOOP - THEN - 1+ - REPEAT - DROP - 1 SWAP 2 DO I prime? IF DROP I THEN LOOP . - ; -`; - const forth = new WAForth(); let jqconsole = $("#console").jqconsole("WAForth\n", ""); diff --git a/src/shell/sieve.js b/src/shell/sieve.js new file mode 100644 index 0000000..27b5f60 --- /dev/null +++ b/src/shell/sieve.js @@ -0,0 +1,22 @@ +// Copied from https://rosettacode.org/wiki/Sieve_of_Eratosthenes#Forth +export default ` + : prime? HERE + C@ 0= ; + : composite! HERE + 1 SWAP C! ; + + : sieve + HERE OVER ERASE + 2 + BEGIN + 2DUP DUP * > + WHILE + DUP prime? IF + 2DUP DUP * DO + I composite! + DUP +LOOP + THEN + 1+ + REPEAT + DROP + 1 SWAP 2 DO I prime? IF DROP I THEN LOOP . + ; +`; diff --git a/src/waforth.wat b/src/waforth.wat index f4108c0..29dc482 100644 --- a/src/waforth.wat +++ b/src/waforth.wat @@ -32,7 +32,7 @@ (define !returnStackBase #x4000) (define !stackBase #x10000) (define !dictionaryBase #x20000) -(define !memorySize (* 1 1024 1024)) +(define !memorySize (* 100 1024 1024)) (define !moduleHeader (string-append diff --git a/tests/benchmarks/sieve/index.html b/tests/benchmarks/sieve/index.html new file mode 100644 index 0000000..486da04 --- /dev/null +++ b/tests/benchmarks/sieve/index.html @@ -0,0 +1,10 @@ + + +
+ +${outputBuffer.join( + "" + )}${(t2 - t1) / 1000.0}