Comments (1)
It's an interesting question.
I wrote a simple test program to measure the throughput of JSON parsing, and compiled it to both wasm and native:
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#ifdef __EMSCRIPTEN__
#include "emscripten.h"
#endif
#include "yyjson.h"
double get_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
#ifdef __EMSCRIPTEN__
EMSCRIPTEN_KEEPALIVE
#endif
int run() {
const char *path = "twitter.json";
const int iter = 30;
const int repeat_per_iter = 100;
#define err(msg) { if (fd) fclose(fd); if (dat) free(dat); printf(msg); return 1; }
char *dat = NULL;
FILE *fd = fopen(path, "rb");
if (!fd) err("failed to open file");
fseek(fd, 0, SEEK_END);
size_t len = ftell(fd);
fseek(fd, 0, SEEK_SET);
if (len == 0) err("empty file");
dat = malloc(len);
if (!dat) err("failed to alloc memory");
if (fread(dat, 1, len, fd) != len) err("failed to read file");
fclose(fd);
fd = NULL;
for(int i = 0; i < iter; i++) {
double t1 = get_time();
for(int j = 0; j < repeat_per_iter; j++) {
yyjson_doc *doc = yyjson_read(dat, len, 0);
if (!doc) err("failed to parse json");
yyjson_doc_free(doc);
}
double t2 = get_time();
double speed = len * repeat_per_iter / (t2 - t1) / 1024.0 / 1024 / 1024;
printf("iter %d: %f ms (%.2fGB/s)\n", i, (t2 - t1) * 1000, speed);
}
free(dat);
return 0;
}
#ifndef __EMSCRIPTEN__
int main() { return run(); }
#endif
emcc -O3 -s WASM=1 -s EXPORTED_RUNTIME_METHODS='["cwrap"]' yyjson.c test.c --embed-file twitter.json
clang -O3 yyjson.c test.c -o test
Chrome: 1.40 GB/s, Native: 3.53 GB/s (M1 Mac)
Chrome: 0.62 GB/s, Native: 1.57 GB/s (Old Mac, 7th gen Intel Core)
I found a more extensive performance test report: https://00f.net/2023/01/04/webassembly-benchmark-2023/ which mentions that
When using the fastest runtime, WebAssembly was only about 2.32 times slower (median)
than native code with architecture-specific optimizations
It seems that the performance of yyjson on wasm is not much different from other libraries.
from yyjson.
Related Issues (20)
- error: -Wno-implicit-int and -Wno-implicit-function-declaration detected HOT 2
- Support Schema validator HOT 1
- A character make fail the JSON (empty JSON) HOT 1
- Does yyjson have parameters to set decimal places? HOT 5
- Discussion / Feedback request: Incorporating bytearray type HOT 8
- incorrectly formatted bool fields. HOT 3
- I need to merge multiple JSON strings HOT 1
- Is there a method to store the array of primitive types? HOT 4
- Release life cycle HOT 3
- Remove static qualifiers to support wrapping in other languages HOT 5
- Report row and line number when generating errors, instead of an absolute position HOT 10
- Improve error messages HOT 1
- write array obj not correctly HOT 2
- Condition for calling read_number_raw HOT 3
- yyjson library can not get value that I try to parse. HOT 1
- Diff two objects to create a patch HOT 2
- New release? HOT 1
- Meson build system support HOT 1
- Define YYJSON_DISABLE_UTILS makes symbol not found HOT 4
- [BUG] Prettify JSON has wrong space when prettifying an array of number HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yyjson.