diff options
author | 2015-02-19 14:51:22 -0800 | |
---|---|---|
committer | 2015-02-19 14:51:22 -0800 | |
commit | 85e4f53c674fae9383c756099281fd4d8b2cb82b (patch) | |
tree | 5ed8f8770aa49f7e9d4bb0c8469c971cf99409f1 /src/node/examples/perf_test.js | |
parent | 929325cee4cdd2dcf6bbdba5d48b6e8f2800ba2c (diff) | |
parent | dca966d39ca15d125bcbc25853ce066410adfeb9 (diff) |
Merge pull request #628 from murgatroid99/node_lint
Added lint to Node tests
Diffstat (limited to 'src/node/examples/perf_test.js')
-rw-r--r-- | src/node/examples/perf_test.js | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/node/examples/perf_test.js b/src/node/examples/perf_test.js index c5e2872736..31083e0987 100644 --- a/src/node/examples/perf_test.js +++ b/src/node/examples/perf_test.js @@ -31,6 +31,8 @@ * */ +'use strict'; + var grpc = require('..'); var testProto = grpc.load(__dirname + '/../interop/test.proto').grpc.testing; var _ = require('underscore'); @@ -44,7 +46,6 @@ function runTest(iterations, callback) { function runIterations(finish) { var start = process.hrtime(); var intervals = []; - var pending = iterations; function next(i) { if (i >= iterations) { testServer.server.shutdown(); @@ -69,28 +70,30 @@ function runTest(iterations, callback) { function warmUp(num) { var pending = num; + function startCall() { + client.emptyCall({}, function(err, resp) { + pending--; + if (pending === 0) { + runIterations(callback); + } + }); + } for (var i = 0; i < num; i++) { - (function(i) { - client.emptyCall({}, function(err, resp) { - pending--; - if (pending === 0) { - runIterations(callback); - } - }); - })(i); + startCall(); } } warmUp(100); } -function percentile(arr, percentile) { - if (percentile > 99) { - percentile = 99; +function percentile(arr, pct) { + if (pct > 99) { + pct = 99; } - if (percentile < 0) { - percentile = 0; + if (pct < 0) { + pct = 0; } - return arr[(arr.length * percentile / 100)|0]; + var index = Math.floor(arr.length * pct / 100); + return arr[index]; } if (require.main === module) { |