You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -299,7 +305,13 @@ Search substrings from the head,
299
305
300
306
```javascript
301
307
var indexArray =sb.indexOf('string');
302
-
var indexArray2 =sb.indexOf(/string/g, offset, limit);
308
+
var indexArray2 =sb.indexOf('string', offset, limit);
309
+
```
310
+
311
+
Search substrings from the head by using RegExp,
312
+
313
+
```javascript
314
+
var indexArray =sb.indexOf(/string/g);
303
315
```
304
316
305
317
Search substrings from the end,
@@ -308,8 +320,6 @@ Search substrings from the end,
308
320
var indexArray =sb.lastIndexOf('string');
309
321
```
310
322
311
-
RegExp is not supported in `lastIndexOf` method.
312
-
313
323
### Equals
314
324
315
325
Determine whether the two strings are the same.
@@ -359,69 +369,73 @@ npm install
359
369
npm run benchmark
360
370
```
361
371
362
-
Here is my report,
372
+
Here is my result,
363
373
364
374
```bash
365
-
Append
366
-
- 44 milliseconds
367
-
✓ natively append text 1000000 times (44ms)
368
-
- 259 milliseconds
369
-
✓ Using StringBuilder to append text 1000000 times (262ms)
370
-
- 43 milliseconds
371
-
✓ Using StringBuilder to append text 1000000 times repeatly (44ms)
372
-
373
-
Insert
374
-
- 53 milliseconds
375
-
✓ natively insert text 10000 times (53ms)
376
-
- 10 milliseconds
377
-
✓ Using StringBuilder to insert text 10000 times
378
-
379
-
Delete
380
-
- 1362 milliseconds
381
-
✓ natively delete text 5000 times (1364ms)
382
-
- 90 milliseconds
383
-
✓ Using StringBuilder to delete text 5000 times (91ms)
384
-
385
-
Replace
386
-
- 1485 milliseconds
387
-
✓ natively replace text 5000 times (1486ms)
388
-
- 90 milliseconds
389
-
✓ Using StringBuilder to replace text 5000 times (91ms)
390
-
391
-
Replace Pattern
392
-
- 39 milliseconds
393
-
✓ natively replace text by using a RegExp pattern (39ms)
394
-
- 666 milliseconds
395
-
✓ Using StringBuilder to replace text by using a pattern (673ms)
396
-
397
-
Equals
398
-
- 1 milliseconds
399
-
✓ natively check the equal 50000 times
400
-
- 14 milliseconds
401
-
✓ Using StringBuilder to check the equal 50000 times
402
-
403
-
EqualsIgnoreCase
404
-
- 6 milliseconds
405
-
✓ natively check the equal 50000 times
406
-
- 53 milliseconds
407
-
✓ Using StringBuilder to check the equal 50000 times (54ms)
408
-
409
-
IndexOf
410
-
- 36 milliseconds
411
-
✓ natively search text
412
-
- 212 milliseconds
413
-
✓ Using StringBuilder to search text (218ms)
414
-
415
-
Reverse
416
-
- 10 milliseconds
417
-
✓ natively reverse text
418
-
- 9 milliseconds
419
-
✓ Using StringBuilder to reverse text
420
-
```
421
-
422
-
According to the result of benchmark, if you just want to append strings, please append them by using native operator `+` instead of this module.
423
-
424
-
And although this module uses Boyer-Moore-MagicLen for searching strings, it still slower than the native implement because the Javascript code is not efficiency enough. It needs to be moved to the native layer(C/C++ code) in the future.
375
+
Append
376
+
- 43 milliseconds
377
+
✓ Natively append text 1000000 times (43ms)
378
+
- 567 milliseconds
379
+
✓ Use StringBuilder to append text 1000000 times (567ms)
380
+
- 1278 milliseconds
381
+
✓ Use StringBuilder to insert text 1000000 times at the end (1287ms)
382
+
- 17 milliseconds
383
+
✓ Use StringBuilder to append text 1000000 times repeatly
384
+
385
+
Insert
386
+
- 92 milliseconds
387
+
✓ Natively insert text 10000 times (92ms)
388
+
- 10 milliseconds
389
+
✓ Use StringBuilder to insert text 10000 times
390
+
391
+
Delete
392
+
- 1427 milliseconds
393
+
✓ Natively delete text 5000 times (1429ms)
394
+
- 87 milliseconds
395
+
✓ Use StringBuilder to delete text 5000 times (88ms)
396
+
397
+
Replace
398
+
- 1511 milliseconds
399
+
✓ Natively replace text 5000 times (1513ms)
400
+
- 85 milliseconds
401
+
✓ Use StringBuilder to replace text 5000 times (86ms)
402
+
403
+
Replace Pattern
404
+
- 37 milliseconds
405
+
✓ Natively replace text with the same length by using a RegExp pattern
406
+
- 20 milliseconds
407
+
✓ Use StringBuilder to replace text with the same length by using a pattern
408
+
- 35 milliseconds
409
+
✓ Natively replace text by using a RegExp pattern
410
+
- 29 milliseconds
411
+
✓ Use StringBuilder to replace text by using a pattern
412
+
413
+
Equals
414
+
- 2 milliseconds
415
+
✓ Natively check the equal 50000 times
416
+
- 13 milliseconds
417
+
✓ Use StringBuilder to check the equal 50000 times
418
+
419
+
EqualsIgnoreCase
420
+
- 21 milliseconds
421
+
✓ Natively check the equal 50000 times
422
+
- 19 milliseconds
423
+
✓ Use StringBuilder to check the equal 50000 times
424
+
425
+
IndexOf
426
+
- 65 milliseconds
427
+
✓ Natively search text (65ms)
428
+
- 2 milliseconds
429
+
✓ Use StringBuilder to search text
430
+
431
+
Reverse
432
+
- 516 milliseconds
433
+
✓ Natively reverse text (516ms)
434
+
- 14 milliseconds
435
+
✓ Use StringBuilder to reverse text
436
+
```
437
+
438
+
According to the result of benchmark, if you just want to append a few different strings, please append them by using native operator `+` instead of this module.
425
439
426
440
## License
427
441
@@ -430,6 +444,5 @@ And although this module uses Boyer-Moore-MagicLen for searching strings, it sti
430
444
## To Do
431
445
432
446
* More test cases
433
-
* Use C/C++ lib to improve the performance
434
447
435
448
If you can help me do this as collaborators, I will be grateful.
0 commit comments