[njs] Added benchmark tests for externals.
Dmitry Volyntsev
xeioex at nginx.com
Tue Mar 17 18:05:39 UTC 2020
details: https://hg.nginx.org/njs/rev/627def6a4630
branches:
changeset: 1355:627def6a4630
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Mar 17 18:33:25 2020 +0300
description:
Added benchmark tests for externals.
diffstat:
src/test/njs_benchmark.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
diffs (79 lines):
diff -r b2bea51069fd -r 627def6a4630 src/test/njs_benchmark.c
--- a/src/test/njs_benchmark.c Mon Mar 16 15:49:51 2020 +0300
+++ b/src/test/njs_benchmark.c Tue Mar 17 18:33:25 2020 +0300
@@ -6,6 +6,8 @@
#include <njs_main.h>
+#include "njs_externals_test.h"
+
#include <string.h>
#include <stdlib.h>
#include <sys/resource.h>
@@ -65,6 +67,11 @@ njs_benchmark_test(njs_vm_t *parent, njs
goto done;
}
+ ret = njs_externals_init(vm);
+ if (ret != NJS_OK) {
+ goto done;
+ }
+
n = test->repeat;
expected = &test->result;
@@ -212,6 +219,27 @@ static njs_benchmark_test_t njs_test[]
njs_str("3524578"),
1 },
+ { "array 64k keys",
+ njs_str("var arr = new Array(2**16);"
+ "arr.fill(1);"
+ "Object.keys(arr)[0]"),
+ njs_str("0"),
+ 10 },
+
+ { "array 64k values",
+ njs_str("var arr = new Array(2**16);"
+ "arr.fill(1);"
+ "Object.values(arr)[0]"),
+ njs_str("1"),
+ 10 },
+
+ { "array 64k entries",
+ njs_str("var arr = new Array(2**16);"
+ "arr.fill(1);"
+ "Object.entries(arr)[0][0]"),
+ njs_str("0"),
+ 10 },
+
{ "array 1M",
njs_str("var arr = new Array(1000000);"
"var count = 0, length = arr.length;"
@@ -229,6 +257,26 @@ static njs_benchmark_test_t njs_test[]
"count"),
njs_str("20000000"),
1 },
+
+ { "external property ($r.uri)",
+ njs_str("$r.uri"),
+ njs_str("АБВ"),
+ 1000 },
+
+ { "external object property ($r.props.a)",
+ njs_str("$r.props.a"),
+ njs_str("1"),
+ 1000 },
+
+ { "external dump (JSON.stringify($r.header))",
+ njs_str("JSON.stringify($r.header)"),
+ njs_str("{\"01\":\"01|АБВ\",\"02\":\"02|АБВ\",\"03\":\"03|АБВ\"}"),
+ 1000 },
+
+ { "external method ($r.some_method('YES'))",
+ njs_str("$r.some_method('YES')"),
+ njs_str("АБВ"),
+ 1000 },
};
More information about the nginx-devel
mailing list