@@ -73,115 +73,6 @@ async function testMutual() { |
73 | 73 | } |
74 | 74 | } |
75 | 75 |
|
76 | | -async function testPerformance() { |
77 | | - const loremIpsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, |
78 | | -sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. |
79 | | -Dui accumsan sit amet nulla facilisi morbi tempus iaculis urna. |
80 | | -Eget dolor morbi non arcu risus quis varius quam quisque. |
81 | | -Lacus viverra vitae congue eu consequat ac felis donec. |
82 | | -Amet porttitor eget dolor morbi non arcu. |
83 | | -Velit ut tortor pretium viverra suspendisse. |
84 | | -Mauris nunc congue nisi vitae suscipit tellus. |
85 | | -Amet nisl suscipit adipiscing bibendum est ultricies integer. |
86 | | -Sit amet dictum sit amet justo donec enim diam. |
87 | | -Condimentum mattis pellentesque id nibh tortor id aliquet lectus proin. |
88 | | -Diam in arcu cursus euismod quis viverra nibh. |
89 | | -`; |
90 | | - |
91 | | - const REPETITIONS = 10000; |
92 | | - const SAMPLE = 100; |
93 | | - const THRESHOLD = 81; |
94 | | - |
95 | | - function getLoremIpsumStream() { |
96 | | - const readable = Readable({ |
97 | | - objectMode: true, |
98 | | - }); |
99 | | - let i = 0; |
100 | | - readable._read = () => readable.push( |
101 | | - i++ >= REPETITIONS ? null : loremIpsum |
102 | | - ); |
103 | | - return readable; |
104 | | - } |
105 | | - |
106 | | - function oldWay() { |
107 | | - const readable = new Readable({ |
108 | | - objectMode: true, |
109 | | - read: () => { |
110 | | - this.resume(); |
111 | | - }, |
112 | | - destroy: (err, cb) => { |
113 | | - this.off('line', lineListener); |
114 | | - this.off('close', closeListener); |
115 | | - this.close(); |
116 | | - cb(err); |
117 | | - }, |
118 | | - }); |
119 | | - const lineListener = (input) => { |
120 | | - if (!readable.push(input)) { |
121 | | - // TODO(rexagod): drain to resume flow |
122 | | - this.pause(); |
123 | | - } |
124 | | - }; |
125 | | - const closeListener = () => { |
126 | | - readable.push(null); |
127 | | - }; |
128 | | - const errorListener = (err) => { |
129 | | - readable.destroy(err); |
130 | | - }; |
131 | | - this.on('error', errorListener); |
132 | | - this.on('line', lineListener); |
133 | | - this.on('close', closeListener); |
134 | | - return readable[Symbol.asyncIterator](); |
135 | | - } |
136 | | - |
137 | | - function getAvg(mean, x, n) { |
138 | | - return (mean * n + x) / (n + 1); |
139 | | - } |
140 | | - |
141 | | - let totalTimeOldWay = 0; |
142 | | - let totalTimeNewWay = 0; |
143 | | - let totalCharsOldWay = 0; |
144 | | - let totalCharsNewWay = 0; |
145 | | - const linesOldWay = []; |
146 | | - const linesNewWay = []; |
147 | | - |
148 | | - for (let time = 0; time < SAMPLE; time++) { |
149 | | - const rlOldWay = readline.createInterface({ |
150 | | - input: getLoremIpsumStream(), |
151 | | - }); |
152 | | - let currenttotalTimeOldWay = Date.now(); |
153 | | - for await (const line of oldWay.call(rlOldWay)) { |
154 | | - totalCharsOldWay += line.length; |
155 | | - if (time === 0) { |
156 | | - linesOldWay.push(line); |
157 | | - } |
158 | | - } |
159 | | - currenttotalTimeOldWay = Date.now() - currenttotalTimeOldWay; |
160 | | - totalTimeOldWay = getAvg(totalTimeOldWay, currenttotalTimeOldWay, SAMPLE); |
161 | | - |
162 | | - const rlNewWay = readline.createInterface({ |
163 | | - input: getLoremIpsumStream(), |
164 | | - }); |
165 | | - let currentTotalTimeNewWay = Date.now(); |
166 | | - for await (const line of rlNewWay) { |
167 | | - totalCharsNewWay += line.length; |
168 | | - if (time === 0) { |
169 | | - linesNewWay.push(line); |
170 | | - } |
171 | | - } |
172 | | - currentTotalTimeNewWay = Date.now() - currentTotalTimeNewWay; |
173 | | - totalTimeNewWay = getAvg(totalTimeNewWay, currentTotalTimeNewWay, SAMPLE); |
174 | | - } |
175 | | - |
176 | | - assert.strictEqual(totalCharsOldWay, totalCharsNewWay); |
177 | | - assert.strictEqual(linesOldWay.length, linesNewWay.length); |
178 | | - linesOldWay.forEach((line, index) => |
179 | | - assert.strictEqual(line, linesNewWay[index]) |
180 | | - ); |
181 | | - const percentage = totalTimeNewWay * 100 / totalTimeOldWay; |
182 | | - assert.ok(percentage <= THRESHOLD, `Failed: ${totalTimeNewWay} isn't lesser than ${THRESHOLD}% of ${totalTimeOldWay}. Actual percentage: ${percentage.toFixed(2)}%`); |
183 | | -} |
184 | | - |
185 | 76 | async function testSlowStreamForLeaks() { |
186 | 77 | const message = 'a\nb\nc\n'; |
187 | 78 | const DELAY = 1; |
@@ -225,6 +116,5 @@ async function testSlowStreamForLeaks() { |
225 | 116 |
|
226 | 117 | testSimple() |
227 | 118 | .then(testMutual) |
228 | | - .then(testPerformance) |
229 | 119 | .then(testSlowStreamForLeaks) |
230 | 120 | .then(common.mustCall()); |