Skip to content

Instantly share code, notes, and snippets.

@nickva
Created February 27, 2023 19:58
Show Gist options
  • Save nickva/08f6100af20d23cde6dbdd65911c02e0 to your computer and use it in GitHub Desktop.
Save nickva/08f6100af20d23cde6dbdd65911c02e0 to your computer and use it in GitHub Desktop.
Overhead comparison QuickJS vs Spidermonkey 91. Measure process startup and context init

Spidermonkey (91), QuickJS (2021-03-27)

Intel MacOS SM91

% ./configure --dev --spidermonkey-version 91 && make
% TIMEFMT=$'Total (sec): \t%*E\nMax RSS(kb): \t%M\n'
% time ./couchjs
Init (usec): 	960.000000
Free (usec): 	827.000000
Total (sec): 	0.015
Max RSS(kb): 	3384

Init (usec): 	755.000000
Free (usec): 	772.000000
Total (sec): 	0.016
Max RSS(kb): 	3336

Init (usec): 	720.000000
Free (usec): 	727.000000
Total (sec): 	0.015
Max RSS(kb): 	3272

Init (usec): 	830.000000
Free (usec): 	874.000000
Total (sec): 	0.016
Max RSS(kb): 	3384

Init (usec): 	738.000000
Free (usec): 	888.000000
Total (sec): 	0.015
Max RSS(kb): 	3404

Init (usec): 	908.000000
Free (usec): 	588.000000
Total (sec): 	0.013
Max RSS(kb): 	3340

Init (usec): 	702.000000
Free (usec): 	721.000000
Total (sec): 	0.015
Max RSS(kb): 	3364

QuickJS Intel MacOS

% ./configure --dev --spidermonkey-version quickjs && make
% TIMEFMT=$'Total (sec): \t%*E\nMax RSS(kb): \t%M\n'
% time ./couchjs

Init (usec): 	372.000000
Free (usec): 	102.000000
Total (sec): 	0.008
Max RSS(kb): 	980

Init (usec): 	391.000000
Free (usec): 	105.000000
Total (sec): 	0.009
Max RSS(kb): 	980

Init (usec): 	375.000000
Free (usec): 	103.000000
Total (sec): 	0.009
Max RSS(kb): 	980

Init (usec): 	368.000000
Free (usec): 	100.000000
Total (sec): 	0.008
Max RSS(kb): 	980

Init (usec): 	399.000000
Free (usec): 	125.000000
Total (sec): 	0.009
Max RSS(kb): 	980

Init (usec): 	397.000000
Free (usec): 	120.000000
Total (sec): 	0.009
Max RSS(kb): 	988

PATCHES

Branch link: https://github.com/nickva/couchdb/tree/qjs-benchmark

SM91

CFLAGS="-DXP_UNIX -I/... -std=c++17 -Wno-invalid-offsetof"
LDFLAGS="-L/... -std=c++17 -lmozjs-91 -lm"
int main(int argc, const char* argv[])
{
    clock_t t0, t1, t2;

    t0 = clock();

    JSContext* cx = NULL;

    JS_Init();

    cx = JS_NewContext(64L * 1024L * 1024L);
    if(cx == NULL) {
        JS_ShutDown();
        return 1;
    }

    t1 = clock();

    JS_DestroyContext(cx);
    JS_ShutDown();

    t2 = clock();

    printf("\nInit (usec): \t%f\n", (double)(t1 - t0) * 1e6 / CLOCKS_PER_SEC);
    printf("Free (usec): \t%f\n",   (double)(t2 - t1) * 1e6 / CLOCKS_PER_SEC);

    return 0;
}

QuickJS

CFLAGS="-flto -Wall -MMD -Wno-array-bounds -Wno-format-truncation -D_GNU_SOURCE -DCONFIG_BIGNUM=0 -O2"
LDFLAGS="-lm -flto"
int main(void) {
  clock_t t0, t1, t2;

  t0 = clock();

  JSRuntime *rt = JS_NewRuntime();
  JS_SetMemoryLimit(rt, 64L * 1024L * 1024L);

  JSContext *ctx = JS_NewContext(rt);

  t1 = clock();

  JS_FreeContext(ctx);
  JS_FreeRuntime(rt);

  t2 = clock();

  printf("\nInit (usec): \t%f\n", (double)(t1 - t0) * 1e6 / CLOCKS_PER_SEC);
  printf("Free (usec): \t%f\n",   (double)(t2 - t1) * 1e6 / CLOCKS_PER_SEC);

  return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment