-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor string benchmark suites and update benchmark results
- Loading branch information
Showing
2 changed files
with
20 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
const { createBenchmarkSuite } = require('../common') | ||
|
||
const suite = createBenchmarkSuite('Check if string starts with a substring') | ||
const suite = createBenchmarkSuite('startsWith comparison') | ||
const shortString = 'foobar' | ||
const longString = 'foobar'.repeat(100) | ||
|
||
const comparison = 'foo' | ||
const comparison2 = 'bar' | ||
|
||
suite.add('(short string) (true) String#startsWith', function () { | ||
suite | ||
.add('(short string) (true) String#startsWith', function () { | ||
shortString.startsWith(comparison) | ||
} | ||
).add('(short string) (true) String#slice and strict comparison', function () { | ||
) | ||
.add('(short string) (true) String#slice and String#indexOf', function () { | ||
shortString.slice(0, comparison.length).indexOf(comparison) === 0 | ||
} | ||
) | ||
.add('(short string) (true) String#slice and strict comparison', function () { | ||
shortString.slice(0, comparison.length) === comparison | ||
} | ||
) | ||
.add('(long string) (true) String#startsWith', function () { | ||
longString.startsWith(comparison) | ||
} | ||
).add('(long string) (true) String#slice and strict comparison', function () { | ||
) | ||
.add('(long string) (true) String#slice and strict comparison', function () { | ||
longString.slice(0, comparison.length) === comparison | ||
} | ||
) | ||
.add('(short string) (false) String#startsWith', function () { | ||
shortString.startsWith(comparison2) | ||
} | ||
).add('(short string) (false) String#slice and strict comparison', function () { | ||
) | ||
.add('(short string) (false) String#slice and strict comparison', function () { | ||
shortString.slice(0, comparison2.length) === comparison2 | ||
} | ||
).add('(long string) (false) String#startsWith', function () { | ||
) | ||
.add('(long string) (false) String#startsWith', function () { | ||
longString.startsWith(comparison2) | ||
} | ||
).add('(long string) (false) String#slice and strict comparison', function () { | ||
) | ||
.add('(long string) (false) String#slice and strict comparison', function () { | ||
longString.slice(0, comparison2.length) === comparison2 | ||
} | ||
).run({ async: false }) | ||
) | ||
.run({ async: false }) |