• karl's avatar
    [es6] Use SubString in String{Starts,Ends}With · d42920ce
    karl authored
    Much faster and constant than always searching the whole string
    
    ````
    var allCodePoints = [];
    for (var i = 0; i < 65536; i++) allCodePoints[i] = i;
    var allCharsString = String.fromCharCode.apply(String, allCodePoints);
    
    function bench(search) {
      var counter = 0;
      print(search + " found at " + allCharsString.startsWith(search));
      var start = Date.now();
      while (counter++ < 5000000) {
        allCharsString.startsWith(search);
      }
      var end = Date.now();
      print(end - start);
      return counter;
    }
    
    print("single character");
    bench("\u0000");
    bench("\u0050");
    bench("\u1000");
    ````
    
    OLD
    
    single character
     found at true
    374
    P found at false
    559
    က found at false
    13492
    
    NEW
    
    single character
     found at true
    261
    P found at false
    146
    က found at false
    146
    
    BUG=v8:4384
    LOG=N
    
    Review URL: https://codereview.chromium.org/1321853006
    
    Cr-Commit-Position: refs/heads/master@{#30599}
    d42920ce
Name
Last commit
Last update
benchmarks Loading commit data...
build Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party/binutils Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.gitignore Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
Makefile.nacl Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...