Skip to content

Commit a597c11

Browse files
mscdexMylesBorins
authored andcommitted
benchmark: improve readability of net benchmarks
PR-URL: #10446 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 994f562 commit a597c11

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

benchmark/net/net-c2s.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,17 @@ Writer.prototype.once = function() {};
6565
Writer.prototype.emit = function() {};
6666

6767

68+
function flow() {
69+
var dest = this.dest;
70+
var res = dest.write(chunk, encoding);
71+
if (!res)
72+
dest.once('drain', this.flow);
73+
else
74+
process.nextTick(this.flow);
75+
}
76+
6877
function Reader() {
69-
this.flow = this.flow.bind(this);
78+
this.flow = flow.bind(this);
7079
this.readable = true;
7180
}
7281

@@ -76,15 +85,6 @@ Reader.prototype.pipe = function(dest) {
7685
return dest;
7786
};
7887

79-
Reader.prototype.flow = function() {
80-
var dest = this.dest;
81-
var res = dest.write(chunk, encoding);
82-
if (!res)
83-
dest.once('drain', this.flow);
84-
else
85-
process.nextTick(this.flow);
86-
};
87-
8888

8989
function server() {
9090
var reader = new Reader();

benchmark/net/net-pipe.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,17 @@ Writer.prototype.once = function() {};
6565
Writer.prototype.emit = function() {};
6666

6767

68+
function flow() {
69+
var dest = this.dest;
70+
var res = dest.write(chunk, encoding);
71+
if (!res)
72+
dest.once('drain', this.flow);
73+
else
74+
process.nextTick(this.flow);
75+
}
76+
6877
function Reader() {
69-
this.flow = this.flow.bind(this);
78+
this.flow = flow.bind(this);
7079
this.readable = true;
7180
}
7281

@@ -76,15 +85,6 @@ Reader.prototype.pipe = function(dest) {
7685
return dest;
7786
};
7887

79-
Reader.prototype.flow = function() {
80-
var dest = this.dest;
81-
var res = dest.write(chunk, encoding);
82-
if (!res)
83-
dest.once('drain', this.flow);
84-
else
85-
process.nextTick(this.flow);
86-
};
87-
8888

8989
function server() {
9090
var reader = new Reader();

benchmark/net/net-s2c.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,17 @@ Writer.prototype.once = function() {};
6565
Writer.prototype.emit = function() {};
6666

6767

68+
function flow() {
69+
var dest = this.dest;
70+
var res = dest.write(chunk, encoding);
71+
if (!res)
72+
dest.once('drain', this.flow);
73+
else
74+
process.nextTick(this.flow);
75+
}
76+
6877
function Reader() {
69-
this.flow = this.flow.bind(this);
78+
this.flow = flow.bind(this);
7079
this.readable = true;
7180
}
7281

@@ -76,15 +85,6 @@ Reader.prototype.pipe = function(dest) {
7685
return dest;
7786
};
7887

79-
Reader.prototype.flow = function() {
80-
var dest = this.dest;
81-
var res = dest.write(chunk, encoding);
82-
if (!res)
83-
dest.once('drain', this.flow);
84-
else
85-
process.nextTick(this.flow);
86-
};
87-
8888

8989
function server() {
9090
var reader = new Reader();

0 commit comments

Comments
 (0)