Welcome! Log In Create A New Profile

Advanced

[njs] Added function micro benchmarks.

Dmitry Volyntsev
April 30, 2021 06:12AM
details: https://hg.nginx.org/njs/rev/282a13ecd193
branches:
changeset: 1627:282a13ecd193
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Apr 30 10:10:57 2021 +0000
description:
Added function micro benchmarks.

diffstat:

src/test/njs_benchmark.c | 52 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 45 insertions(+), 7 deletions(-)

diffs (98 lines):

diff -r 0746b2ed76cc -r 282a13ecd193 src/test/njs_benchmark.c
--- a/src/test/njs_benchmark.c Fri Apr 16 13:46:46 2021 +0000
+++ b/src/test/njs_benchmark.c Fri Apr 30 10:10:57 2021 +0000
@@ -35,7 +35,7 @@ njs_benchmark_test(njs_vm_t *parent, njs
{
u_char *start;
njs_vm_t *vm, *nvm;
- uint64_t us;
+ uint64_t ns;
njs_int_t ret, proto_id;
njs_str_t s, *expected;
njs_uint_t i, n;
@@ -76,7 +76,7 @@ njs_benchmark_test(njs_vm_t *parent, njs
expected = &test->result;

ret = NJS_ERROR;
- us = njs_time() / 1000;
+ ns = njs_time();

for (i = 0; i < n; i++) {

@@ -105,18 +105,18 @@ njs_benchmark_test(njs_vm_t *parent, njs
nvm = NULL;
}

- us = njs_time() / 1000 - us;
+ ns = njs_time() - ns;

if (!opts->dump_report) {
if (n == 1) {
njs_printf("%s%s: %.3fs\n", opts->previous ? " " : "",
- test->name, (double) us / 1000000);
+ test->name, (double) ns / 1000000000);

} else {
njs_printf("%s%s: %.3fµs, %d times/s\n",
opts->previous ? " " : "",
- test->name, (double) us / n,
- (int) ((uint64_t) n * 1000000 / us));
+ test->name, (double) ns / n / 1000,
+ (int) ((uint64_t) n * 1000000000 / ns));
}
}

@@ -133,7 +133,7 @@ njs_benchmark_test(njs_vm_t *parent, njs
goto done;
}

- njs_value_number_set(&usec, us);
+ njs_value_number_set(&usec, 1000 * ns);
njs_value_number_set(&times, n);

ret = njs_vm_object_alloc(parent, result, &name_key, &name,
@@ -165,6 +165,44 @@ static njs_benchmark_test_t njs_test[]
njs_str("null"),
1000000 },

+ { "func call",
+ njs_str("function test(a) { return 1 }"
+ ""
+ "test(1);"
+ "test(1);"
+ "test(1);"
+ "test(1);"),
+ njs_str("1"),
+ 100000 },
+
+ { "func call (3 local functions)",
+ njs_str("function test(a) { "
+ " function g(x) {}"
+ " function h(x) {}"
+ " function f(x) {}"
+ " return 1;"
+ "}"
+ ""
+ "test(1);"
+ "test(1);"
+ "test(1);"
+ "test(1);"),
+ njs_str("1"),
+ 100000 },
+
+ { "closure var global",
+ njs_str("function test(a) { sum++ }"
+ ""
+ "var sum = 0;"
+ ""
+ "test(1);"
+ "test(1);"
+ "test(1);"
+ "test(1);"
+ "sum"),
+ njs_str("4"),
+ 100000 },
+
{ "JSON.parse",
njs_str("JSON.parse('{\"a\":123, \"XXX\":[3,4,null]}').a"),
njs_str("123"),
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Added function micro benchmarks.

Dmitry Volyntsev 68 April 30, 2021 06:12AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 77
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready