Skip to content

Commit 8a7d6b9

Browse files
committed
fix benchmark
1 parent 360ada6 commit 8a7d6b9

File tree

2 files changed

+73
-64
lines changed

2 files changed

+73
-64
lines changed

benchmark/benchmark.js

+72-63
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const mlog = require('mocha-logger');
66
const StringBuilder = require('../index');
77

88
describe('Append', function() {
9+
this.timeout(15000);
910
var a = 'The first string.'
1011
var b = 'The second string.'
1112
var c = 'The third string.'
@@ -52,6 +53,7 @@ describe('Append', function() {
5253
});
5354

5455
describe('Insert', function() {
56+
this.timeout(15000);
5557
var a = 'This is a simple example demonstrating how to use this module.';
5658
var b = '12345';
5759
var startTime, endTime;
@@ -83,6 +85,7 @@ describe('Insert', function() {
8385
});
8486

8587
describe('Delete', function() {
88+
this.timeout(15000);
8689
var a = '';
8790
for (let i = 0; i < 10000; ++i) {
8891
a += 'This is a simple example demonstrating how to use this module.';
@@ -116,6 +119,7 @@ describe('Delete', function() {
116119
});
117120

118121
describe('Replace', function() {
122+
this.timeout(15000);
119123
var a = '';
120124
for (let i = 0; i < 10000; ++i) {
121125
a += 'This is a simple example demonstrating how to use this module.';
@@ -151,50 +155,52 @@ describe('Replace', function() {
151155
});
152156

153157
describe('Replace Pattern', function() {
154-
var a = '';
155-
for(let i = 0; i < 1000000; ++i){
156-
a += 'This text.';
157-
}
158-
var b = '';
159-
for(let i = 0; i < 1000000; ++i){
160-
b += 'This text.';
161-
}
162-
var startTime, endTime;
163-
164-
it('Natively replace text with the same length by using a RegExp pattern', function() {
165-
var s = a;
166-
startTime = Date.now();
167-
s = s.replace(/This/g, 'this');
168-
endTime = Date.now();
169-
mlog.log(endTime - startTime, 'milliseconds');
170-
});
171-
172-
it('Use StringBuilder to replace text with the same length by using a pattern', function() {
173-
var sb = new StringBuilder(a);
174-
startTime = Date.now();
175-
sb.replaceAll('This', 'this');
176-
endTime = Date.now();
177-
mlog.log(endTime - startTime, 'milliseconds');
178-
});
179-
180-
it('Natively replace text by using a RegExp pattern', function() {
181-
var s = b;
182-
startTime = Date.now();
183-
s = s.replace(/This/g, 'The');
184-
endTime = Date.now();
185-
mlog.log(endTime - startTime, 'milliseconds');
186-
});
187-
188-
it('Use StringBuilder to replace text by using a pattern', function() {
189-
var sb = new StringBuilder(b);
190-
startTime = Date.now();
191-
sb.replaceAll('This', 'The');
192-
endTime = Date.now();
193-
mlog.log(endTime - startTime, 'milliseconds');
194-
});
158+
this.timeout(15000);
159+
var a = '';
160+
for(let i = 0; i < 1000000; ++i){
161+
a += 'This text.';
162+
}
163+
var b = '';
164+
for(let i = 0; i < 1000000; ++i){
165+
b += 'This text.';
166+
}
167+
var startTime, endTime;
168+
169+
it('Natively replace text with the same length by using a RegExp pattern', function() {
170+
var s = a;
171+
startTime = Date.now();
172+
s = s.replace(/This/g, 'this');
173+
endTime = Date.now();
174+
mlog.log(endTime - startTime, 'milliseconds');
175+
});
176+
177+
it('Use StringBuilder to replace text with the same length by using a pattern', function() {
178+
var sb = new StringBuilder(a);
179+
startTime = Date.now();
180+
sb.replaceAll('This', 'this');
181+
endTime = Date.now();
182+
mlog.log(endTime - startTime, 'milliseconds');
183+
});
184+
185+
it('Natively replace text by using a RegExp pattern', function() {
186+
var s = b;
187+
startTime = Date.now();
188+
s = s.replace(/This/g, 'The');
189+
endTime = Date.now();
190+
mlog.log(endTime - startTime, 'milliseconds');
191+
});
192+
193+
it('Use StringBuilder to replace text by using a pattern', function() {
194+
var sb = new StringBuilder(b);
195+
startTime = Date.now();
196+
sb.replaceAll('This', 'The');
197+
endTime = Date.now();
198+
mlog.log(endTime - startTime, 'milliseconds');
199+
});
195200
});
196201

197202
describe('Equals', function() {
203+
this.timeout(15000);
198204
var a = 'The first string.'
199205
var b = 'The second string.'
200206
var c = 'The third string.'
@@ -260,6 +266,7 @@ describe('Equals', function() {
260266
});
261267

262268
describe('EqualsIgnoreCase', function() {
269+
this.timeout(15000);
263270
var a = 'The first string.'
264271
var b = 'The second string.'
265272
var c = 'The third string.'
@@ -326,6 +333,7 @@ describe('EqualsIgnoreCase', function() {
326333
});
327334

328335
describe('IndexOf', function() {
336+
this.timeout(15000);
329337
var a = '';
330338
for (let i = 0; i < 1000000; ++i) {
331339
a += 'COO';
@@ -364,26 +372,27 @@ describe('IndexOf', function() {
364372
});
365373

366374
describe('Reverse', function() {
367-
var a = '';
368-
for(let i = 0; i < 100000; ++i){
369-
a += 'HERE IS A SIMPLE EXAMPLE, WHICH CONTAINS MULTIPLE EXAMPLES. SIXLEE IS A WRONG WORD. EXAMPLEEXAMPLE';
370-
}
371-
var p = 'EXAMPLE';
372-
var startTime, endTime;
373-
374-
it('Natively reverse text', function() {
375-
var s = a;
376-
startTime = Date.now();
377-
var reverse = s.split('').reverse().join('');
378-
endTime = Date.now();
379-
mlog.log(endTime - startTime, 'milliseconds');
380-
});
381-
382-
it('Use StringBuilder to reverse text', function() {
383-
var sb = new StringBuilder(a);
384-
startTime = Date.now();
385-
var reverse = sb.reverse();
386-
endTime = Date.now();
387-
mlog.log(endTime - startTime, 'milliseconds');
388-
});
375+
this.timeout(15000);
376+
var a = '';
377+
for(let i = 0; i < 100000; ++i){
378+
a += 'HERE IS A SIMPLE EXAMPLE, WHICH CONTAINS MULTIPLE EXAMPLES. SIXLEE IS A WRONG WORD. EXAMPLEEXAMPLE';
379+
}
380+
var p = 'EXAMPLE';
381+
var startTime, endTime;
382+
383+
it('Natively reverse text', function() {
384+
var s = a;
385+
startTime = Date.now();
386+
var reverse = s.split('').reverse().join('');
387+
endTime = Date.now();
388+
mlog.log(endTime - startTime, 'milliseconds');
389+
});
390+
391+
it('Use StringBuilder to reverse text', function() {
392+
var sb = new StringBuilder(a);
393+
startTime = Date.now();
394+
var reverse = sb.reverse();
395+
endTime = Date.now();
396+
mlog.log(endTime - startTime, 'milliseconds');
397+
});
389398
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-stringbuilder",
3-
"version": "2.2.2",
3+
"version": "2.2.3",
44
"description": "An easy and fast in-memory string builder for Node.js.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)