Skip to content

Commit 76ebae4

Browse files
joyeecheungtargos
authored andcommitted
benchmark: make the benchmark tool work with Node 10
Avoid using class fields in the benchmark tools since they are not available in Node 10. This can be reverted when Node 10 reaches EOL. PR-URL: #35817 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Mary Marchini <oss@mmarchini.me>
1 parent 9b549c1 commit 76ebae4

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

‎benchmark/common.js‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ const child_process = require('child_process');
44
consthttp_benchmarkers=require('./_http-benchmarkers.js');
55

66
classBenchmark{
7-
// Used to make sure a benchmark only start a timer once
8-
#started =false;
7+
constructor(fn,configs,options={}){
8+
// Used to make sure a benchmark only start a timer once
9+
this._started=false;
910

10-
// Indicate that the benchmark ended
11-
#ended=false;
11+
// Indicate that the benchmark ended
12+
this._ended=false;
1213

13-
// Holds process.hrtime value
14-
#time=[0,0];
14+
// Holds process.hrtime value
15+
this._time=[0,0];
1516

16-
// Use the file name as the name of the benchmark
17-
name=require.main.filename.slice(__dirname.length+1);
17+
// Use the file name as the name of the benchmark
18+
this.name=require.main.filename.slice(__dirname.length+1);
1819

19-
// Execution arguments i.e. flags used to run the jobs
20-
flags=process.env.NODE_BENCHMARK_FLAGS ?
21-
process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) :
22-
[];
20+
// Execution arguments i.e. flags used to run the jobs
21+
this.flags=process.env.NODE_BENCHMARK_FLAGS ?
22+
process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) :
23+
[];
2324

24-
constructor(fn,configs,options={}){
2525
// Parse job-specific configuration from the command line arguments
2626
constargv=process.argv.slice(2);
2727
constparsed_args=this._parseArgs(argv,configs,options);
@@ -214,21 +214,21 @@ class Benchmark {
214214
}
215215

216216
start(){
217-
if(this.#started){
217+
if(this._started){
218218
thrownewError('Called start more than once in a single benchmark');
219219
}
220-
this.#started=true;
221-
this.#time=process.hrtime();
220+
this._started=true;
221+
this._time=process.hrtime();
222222
}
223223

224224
end(operations){
225225
// Get elapsed time now and do error checking later for accuracy.
226-
constelapsed=process.hrtime(this.#time);
226+
constelapsed=process.hrtime(this._time);
227227

228-
if(!this.#started){
228+
if(!this._started){
229229
thrownewError('called end without start');
230230
}
231-
if(this.#ended){
231+
if(this._ended){
232232
thrownewError('called end multiple times');
233233
}
234234
if(typeofoperations!=='number'){
@@ -244,7 +244,7 @@ class Benchmark {
244244
elapsed[1]=1;
245245
}
246246

247-
this.#ended=true;
247+
this._ended=true;
248248
consttime=elapsed[0]+elapsed[1]/1e9;
249249
constrate=operations/time;
250250
this.report(rate,elapsed);

0 commit comments

Comments
 (0)