jsonpath-wasm 성능비교 추가

This commit is contained in:
freestrings 2019-03-08 17:27:24 +09:00
parent 873eebd157
commit ba57ae0ea5
25 changed files with 6210 additions and 29 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "jsonpath_lib" name = "jsonpath_lib"
version = "0.1.1" version = "0.1.2"
authors = ["Changseok Han <freestrings@gmail.com>"] authors = ["Changseok Han <freestrings@gmail.com>"]
description = "JsonPath in Rust and Webassembly - Webassembly Demo: https://freestrings.github.io/jsonpath" description = "JsonPath in Rust and Webassembly - Webassembly Demo: https://freestrings.github.io/jsonpath"

View File

@ -1,6 +1,7 @@
# jsonpath-lib # jsonpath-lib
[![Build Status](https://travis-ci.org/freestrings/jsonpath.svg?branch=master)](https://travis-ci.org/freestrings/jsonpath) [![Build Status](https://travis-ci.org/freestrings/jsonpath.svg?branch=master)](https://travis-ci.org/freestrings/jsonpath)
[![version](https://img.shields.io/crates/v/:jsonpath.svg)](https://crates.io/crates/jsonpath_lib)
`Rust` 버전 [JsonPath](https://goessner.net/articles/JsonPath/) 구현이다. Rust 구현과 동일한 기능을 `Webassembly` 로 제공하는 것도 목표. `Rust` 버전 [JsonPath](https://goessner.net/articles/JsonPath/) 구현이다. Rust 구현과 동일한 기능을 `Webassembly` 로 제공하는 것도 목표.
@ -30,7 +31,7 @@ To enjoy Rust!
[With AWS API Gateway](#with-aws-api-gateway) [With AWS API Gateway](#with-aws-api-gateway)
[Benchmark](#benchmark) [Simple time check](#simple-time-check-with-dchesterjsonpath)
## With Javascript (WebAssembly) ## With Javascript (WebAssembly)
@ -545,5 +546,64 @@ assert_eq!(ret, json);
- -
## Benchmark ## Simple time check with [dchester/jsonpath](https://github.com/dchester/jsonpath)
`jsonpath` is dchester/jsonpath `jsonpath-wasm` is freestrings/jsonpath's compiled to webassembly
`jsonpath-wasm` is slow performance on Chrome browser and in NodeJS. not yet usable. :)
### Browser [Bench Demo](https://freestrings.github.io/jsonpath/bench)
#### Chrome: 72.0
> Something to wrong in chrome
```
jsonpath, 134
jsonpath-wasm- reader, 1409
jsonpath-wasm- compile, 3237
jsonpath-wasm- read, 5302
```
#### Firefox: 65.0
> jsonpath-wasm is faster than jsonpath
```
jsonpath, 301
jsonpath-wasm- reader, 166
jsonpath-wasm- compile, 130
jsonpath-wasm- read, 144
```
### NodeJs
* NodeJS: 11.0
* CPU: Intel Core i5-4460
* Memory: 16GB
> Rust > jsonpath > jsonpath-wasm
```bash
cd benches && ./bench_node_vs_rust.sh
$..book[?(@.price<30 && @.category==fiction)] (loop 100,000)
Rust:
real 0m1.141s
user 0m1.137s
sys 0m0.004s
NodeJs - jsonpath module:
real 0m3.718s
user 0m4.175s
sys 0m0.050s
NodeJs - jsonpath-wasm module:
real 0m10.205s
user 0m10.281s
sys 0m0.383s
```

View File

@ -10,4 +10,6 @@ printf "\n\n"
echo "Rust: " && time ./bench.sh echo "Rust: " && time ./bench.sh
printf "\n" printf "\n"
cd "${DIR}"/javascript && echo "NodeJs: " && time ./bench.sh cd "${DIR}"/javascript && echo "NodeJs - jsonpath module: " && time ./bench.sh jsonpathOnly
printf "\n"
cd "${DIR}"/javascript && echo "NodeJs - jsonpath-wasm module: " && time ./bench.sh jsonpathWasmOnly

View File

@ -37,7 +37,7 @@ let json = {
}; };
const jp = require('jsonpath'); const jp = require('jsonpath');
const jpw = require('jsonpath-wasm'); const jpw = require('@nodejs/jsonpath-wasm');
const Benchmark = require('benchmark'); const Benchmark = require('benchmark');
function compareJsonpath(path) { function compareJsonpath(path) {
@ -84,12 +84,19 @@ function compareEmptyFunction() {
function jsonpathOnly() { function jsonpathOnly() {
for(var i = 0; i < 100000 ; i++) { for(var i = 0; i < 100000 ; i++) {
let _ = jp.query(json, '$..book[?(@.price<30 && @.category==\"fiction\")]'); let _ = jp.query(json, '$..book[?(@.price<30 && @.category=="fiction")]');
}
}
function jsonpathWasmOnly() {
let reader = jpw.reader(json);
for(var i = 0; i < 100000 ; i++) {
let _ = reader('$..book[?(@.price<30 && @.category=="fiction")]');
} }
} }
if(process.argv.length < 3) { if(process.argv.length < 3) {
let functions = ['', 'compareJsonpath', 'compareEmptyFunction', 'jsonpathOnly']; let functions = ['', 'compareJsonpath', 'compareEmptyFunction', 'jsonpathOnly', 'jsonpathWasmOnly'];
console.log("node bench.js", functions.join("\n\t|")); console.log("node bench.js", functions.join("\n\t|"));
return; return;
} }
@ -98,11 +105,14 @@ let functionName = process.argv[2];
switch (functionName) { switch (functionName) {
case 'compareJsonpath': case 'compareJsonpath':
compareJsonpath('$..book[?(@.price<30 && @.category==\"fiction\")]'); compareJsonpath('$..book[?(@.price<30 && @.category=="fiction")]');
break; break;
case 'compareEmptyFunction': case 'compareEmptyFunction':
compareEmptyFunction(); compareEmptyFunction();
break; break;
case 'jsonpathWasmOnly':
jsonpathWasmOnly();
break;
default: default:
jsonpathOnly(); jsonpathOnly();
} }

View File

@ -1,2 +1,2 @@
#!/bin/bash #!/bin/bash
node bench.js jsonpathOnly node bench.js $1

View File

@ -117,9 +117,6 @@
"underscore": "1.7.0" "underscore": "1.7.0"
} }
}, },
"jsonpath-wasm": {
"version": "0.1.1"
},
"levn": { "levn": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",

View File

@ -7,7 +7,6 @@
}, },
"dependencies": { "dependencies": {
"jsonpath": "*", "jsonpath": "*",
"jsonpath-wasm": "*",
"benchmark": "*" "benchmark": "*"
} }
} }

View File

@ -1,5 +0,0 @@
#!/bin/bash
set -e
cd ../../wasm && ./build.sh nodejs
cd ../benches/javascript && npm link jsonpath-wasm

38
docs/bench/0.bootstrap.js Normal file

File diff suppressed because one or more lines are too long

25
docs/bench/1.bootstrap.js Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

294
docs/bench/bootstrap.js vendored Normal file
View File

@ -0,0 +1,294 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ function webpackJsonpCallback(data) {
/******/ var chunkIds = data[0];
/******/ var moreModules = data[1];
/******/
/******/
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, resolves = [];
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId]) {
/******/ resolves.push(installedChunks[chunkId][0]);
/******/ }
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(data);
/******/
/******/ while(resolves.length) {
/******/ resolves.shift()();
/******/ }
/******/
/******/ };
/******/
/******/
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
/******/ // Promise = chunk loading, 0 = chunk loaded
/******/ var installedChunks = {
/******/ "main": 0
/******/ };
/******/
/******/
/******/
/******/ // script path function
/******/ function jsonpScriptSrc(chunkId) {
/******/ return __webpack_require__.p + "" + chunkId + ".bootstrap.js"
/******/ }
/******/
/******/ // object to store loaded and loading wasm modules
/******/ var installedWasmModules = {};
/******/
/******/ function promiseResolve() { return Promise.resolve(); }
/******/
/******/ var wasmImportObjects = {
/******/ "../browser_pkg/jsonpath_wasm_bg.wasm": function() {
/******/ return {
/******/ "./jsonpath_wasm": {
/******/ "__wbindgen_json_parse": function(p0i32,p1i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_json_parse"](p0i32,p1i32);
/******/ },
/******/ "__wbindgen_json_serialize": function(p0i32,p1i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_json_serialize"](p0i32,p1i32);
/******/ },
/******/ "__wbindgen_cb_forget": function(p0i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_cb_forget"](p0i32);
/******/ },
/******/ "__wbindgen_object_drop_ref": function(p0i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_object_drop_ref"](p0i32);
/******/ },
/******/ "__wbindgen_string_new": function(p0i32,p1i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_string_new"](p0i32,p1i32);
/******/ },
/******/ "__wbindgen_is_string": function(p0i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_is_string"](p0i32);
/******/ },
/******/ "__wbindgen_string_get": function(p0i32,p1i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_string_get"](p0i32,p1i32);
/******/ },
/******/ "__wbindgen_object_clone_ref": function(p0i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_object_clone_ref"](p0i32);
/******/ },
/******/ "__wbindgen_throw": function(p0i32,p1i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_throw"](p0i32,p1i32);
/******/ },
/******/ "__wbindgen_closure_wrapper33": function(p0i32,p1i32,p2i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_closure_wrapper33"](p0i32,p1i32,p2i32);
/******/ },
/******/ "__wbindgen_closure_wrapper35": function(p0i32,p1i32,p2i32) {
/******/ return installedModules["../browser_pkg/jsonpath_wasm.js"].exports["__wbindgen_closure_wrapper35"](p0i32,p1i32,p2i32);
/******/ }
/******/ }
/******/ };
/******/ },
/******/ };
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = function requireEnsure(chunkId) {
/******/ var promises = [];
/******/
/******/
/******/ // JSONP chunk loading for javascript
/******/
/******/ var installedChunkData = installedChunks[chunkId];
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
/******/
/******/ // a Promise means "currently loading".
/******/ if(installedChunkData) {
/******/ promises.push(installedChunkData[2]);
/******/ } else {
/******/ // setup Promise in chunk cache
/******/ var promise = new Promise(function(resolve, reject) {
/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject];
/******/ });
/******/ promises.push(installedChunkData[2] = promise);
/******/
/******/ // start chunk loading
/******/ var script = document.createElement('script');
/******/ var onScriptComplete;
/******/
/******/ script.charset = 'utf-8';
/******/ script.timeout = 120;
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = jsonpScriptSrc(chunkId);
/******/
/******/ onScriptComplete = function (event) {
/******/ // avoid mem leaks in IE.
/******/ script.onerror = script.onload = null;
/******/ clearTimeout(timeout);
/******/ var chunk = installedChunks[chunkId];
/******/ if(chunk !== 0) {
/******/ if(chunk) {
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
/******/ var realSrc = event && event.target && event.target.src;
/******/ var error = new Error('Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')');
/******/ error.type = errorType;
/******/ error.request = realSrc;
/******/ chunk[1](error);
/******/ }
/******/ installedChunks[chunkId] = undefined;
/******/ }
/******/ };
/******/ var timeout = setTimeout(function(){
/******/ onScriptComplete({ type: 'timeout', target: script });
/******/ }, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ document.head.appendChild(script);
/******/ }
/******/ }
/******/
/******/ // Fetch + compile chunk loading for webassembly
/******/
/******/ var wasmModules = {"0":["../browser_pkg/jsonpath_wasm_bg.wasm"]}[chunkId] || [];
/******/
/******/ wasmModules.forEach(function(wasmModuleId) {
/******/ var installedWasmModuleData = installedWasmModules[wasmModuleId];
/******/
/******/ // a Promise means "currently loading" or "already loaded".
/******/ if(installedWasmModuleData)
/******/ promises.push(installedWasmModuleData);
/******/ else {
/******/ var importObject = wasmImportObjects[wasmModuleId]();
/******/ var req = fetch(__webpack_require__.p + "" + {"../browser_pkg/jsonpath_wasm_bg.wasm":"95acaf85df86c0a76234"}[wasmModuleId] + ".module.wasm");
/******/ var promise;
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {
/******/ return WebAssembly.instantiate(items[0], items[1]);
/******/ });
/******/ } else if(typeof WebAssembly.instantiateStreaming === 'function') {
/******/ promise = WebAssembly.instantiateStreaming(req, importObject);
/******/ } else {
/******/ var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });
/******/ promise = bytesPromise.then(function(bytes) {
/******/ return WebAssembly.instantiate(bytes, importObject);
/******/ });
/******/ }
/******/ promises.push(installedWasmModules[wasmModuleId] = promise.then(function(res) {
/******/ return __webpack_require__.w[wasmModuleId] = (res.instance || res).exports;
/******/ }));
/******/ }
/******/ });
/******/ return Promise.all(promises);
/******/ };
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // on error function for async loading
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
/******/
/******/ // object with all WebAssembly.instance exports
/******/ __webpack_require__.w = {};
/******/
/******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || [];
/******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);
/******/ jsonpArray.push = webpackJsonpCallback;
/******/ jsonpArray = jsonpArray.slice();
/******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);
/******/ var parentJsonpFunction = oldJsonpFunction;
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./bootstrap.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./bootstrap.js":
/*!**********************!*\
!*** ./bootstrap.js ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
eval("// A dependency graph that contains any wasm must all be imported\n// asynchronously. This `bootstrap.js` file does the single async import, so\n// that no one else needs to worry about it again.\nPromise.all(/*! import() */[__webpack_require__.e(1), __webpack_require__.e(0)]).then(__webpack_require__.bind(null, /*! ./index.js */ \"./index.js\"))\n .catch(e => console.error(\"Error importing `index.js`:\", e));\n\n//# sourceURL=webpack:///./bootstrap.js?");
/***/ })
/******/ });

18
docs/bench/index.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jsonpath vs jsonpath-wasm simple performance comparision</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body role="document">
<div class="container">
<h3 style="margin-top: 15px;">jsonpath vs jsonpath-wasm simple performance comparision</h3>
</div>
<script src="./bootstrap.js"></script>
<script>
</script>
</body>
</html>

2
wasm/.gitignore vendored
View File

@ -1,4 +1,4 @@
/target target
**/*.rs.bk **/*.rs.bk
Cargo.lock Cargo.lock
bin/ bin/

View File

@ -1,6 +1,6 @@
[package] [package]
name = "jsonpath-wasm" name = "jsonpath-wasm"
version = "0.1.1" version = "0.1.2"
authors = ["Changseok Han <freestrings@gmail.com>"] authors = ["Changseok Han <freestrings@gmail.com>"]
description = "JsonPath Webassembly version compiled by Rust - Demo: https://freestrings.github.io/jsonpath" description = "JsonPath Webassembly version compiled by Rust - Demo: https://freestrings.github.io/jsonpath"

View File

@ -2,11 +2,42 @@
set -e set -e
cd ./www && \ # project_root/wasm
rm -rf dist && \ DIR="$(pwd)"
rm -rf node_modules && \
cd "${DIR}"/www && \
rm -rf "${DIR}"/dist && \
rm -rf "${DIR}"/node_modules && \
npm install && \ npm install && \
cd .. && \ cd "${DIR}"
wasm-pack build --target=$1 && \
cd pkg && npm link && \ echo "-------------------- start build nodejs pkg --------------------"
cd ../www && npm link jsonpath-wasm echo
rm -rf "${DIR}"/wasm/nodejs_pkg && \
wasm-pack build --target=nodejs --scope nodejs --out-dir nodejs_pkg && \
cd "${DIR}"/nodejs_pkg && npm link && \
rm -rf "${DIR}"/../benches/javascript/node_modules && \
cd "${DIR}"/../benches/javascript && npm install && \
npm link @nodejs/jsonpath-wasm
echo "-------------------- build nodejs pkg done --------------------"
cd "${DIR}"
echo
echo
echo "-------------------- start build browser pkg --------------------"
echo
rm -rf "${DIR}"/wasm/browser_pkg && \
wasm-pack build --target=browser --scope browser --out-dir browser_pkg && \
cd "${DIR}"/browser_pkg && npm link && \
cd "${DIR}"/www && npm link @browser/jsonpath-wasm
echo "-------------------- build browser pkg done --------------------"
echo
echo
echo "-------------------- start build browser bench pkg --------------------"
echo
rm -rf "${DIR}"/www_bench/node_modules && \
cd "${DIR}"/www_bench && npm install && npm link @browser/jsonpath-wasm
echo "-------------------- build browser bench pkg done --------------------"

1
wasm/node_modules/jsonpath-wasm generated vendored
View File

@ -1 +0,0 @@
../../../../../.nvm/versions/node/v11.10.1/lib/node_modules/jsonpath-wasm

View File

@ -1,4 +1,4 @@
import * as jsonpath from "jsonpath-wasm"; import * as jsonpath from "@browser/jsonpath-wasm";
function getTextarea() { function getTextarea() {
return document.querySelector('#json-example'); return document.querySelector('#json-example');

2
wasm/www_bench/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

5
wasm/www_bench/bootstrap.js vendored Normal file
View File

@ -0,0 +1,5 @@
// A dependency graph that contains any wasm must all be imported
// asynchronously. This `bootstrap.js` file does the single async import, so
// that no one else needs to worry about it again.
import("./index.js")
.catch(e => console.error("Error importing `index.js`:", e));

18
wasm/www_bench/index.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jsonpath vs jsonpath-wasm simple performance comparision</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body role="document">
<div class="container">
<h3 style="margin-top: 15px;">jsonpath vs jsonpath-wasm simple performance comparision</h3>
</div>
<script src="./bootstrap.js"></script>
<script>
</script>
</body>
</html>

65
wasm/www_bench/index.js Normal file
View File

@ -0,0 +1,65 @@
import * as jpw from "@browser/jsonpath-wasm";
import * as jp from "jsonpath/jsonpath.js";
function run(message, iter, cb) {
let d = Date.now();
for (let i = 0; i < iter; i++) {
cb();
}
msg([message, Date.now() - d].join(", "));
}
function msg(msg) {
console.log(msg);
let div = document.createElement("div");
div.innerText = msg;
document.body.appendChild(div);
}
let json = {
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
};
setTimeout(function() {
let path = '$..book[?(@.price<30 && @.category=="fiction")]';
let template = jpw.compile(path);
let reader = jpw.reader(json);
run('jsonpath', 1000, function() { jp.query(json, path) });
run('jsonpath-wasm- reader', 1000, function() { reader(path) });
run('jsonpath-wasm- compile', 1000, function() { template(json) });
run('jsonpath-wasm- read', 1000, function() { jpw.read(json, path) });
}, 0);

5574
wasm/www_bench/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
{
"name": "jsonpath-wasm",
"version": "0.1.0",
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"start": "webpack-dev-server"
},
"repository": {
"type": "git",
"url": "git+https://github.com/freestrings/jsonpath.git"
},
"keywords": [
"webassembly",
"wasm",
"rust",
"webpack",
"jsonpath"
],
"author": "Changseok Han <freestrings@gmail.com>",
"license": "(MIT OR Apache-2.0)",
"bugs": {
"url": "https://github.com/freestrings/jsonpath/issues"
},
"homepage": "https://github.com/freestrings/jsonpath#readme",
"devDependencies": {
"copy-webpack-plugin": "^5.0.0",
"webpack": "^4.29.6",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
},
"dependencies": {
"jsonpath": "*"
}
}

View File

@ -0,0 +1,14 @@
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require('path');
module.exports = {
entry: "./bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
mode: "development",
plugins: [
new CopyWebpackPlugin(['index.html'])
]
};