nano-id browser optimizations

JavaScript performance comparison

Test case created by sbrichardson

Preparation code

<script>
url = 'Uint8ArdomValuesObj012345679BCDEFGHIJKLMNPQRSTWXYZ_cfghkpqvwxyz-'

urlLen = url.length

</script>
      
<script>
Benchmark.prototype.setup = function() {
  var len = 64
  var random = window.crypto.getRandomValues(new Uint8Array(len))

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
original nanoid-browser
let i = len,
  s = ''
    
while (0 < i--) {
  s += url[random[i] & 63]
}
pending…
manual assignment
let i = len,
  s = ''
    
while (0 < i--) {
  s = s + url[random[i] & 63]
}
pending…
remove < 0 comparison
let i = len,
  s = ''
    
while (i--) {
  s += url[random[i] & 63]
}
pending…
combined comparison, assign
let i = len,
  s = ''
    
while (i--) {
  s = s + url[random[i] & 63]
}
pending…
combined modulo, comparison, assign
let i = len,
  s = ''
    
while (i--) {
  s = s + url[random[i] % 63]
}
pending…
modulo instead of bitwise &
let i = len,
  s = ''
    
while (0 < i--) {
  s += url[random[i] % 63]
}
pending…
url length stored in variable
let i = len,
  s = ''
    
while (0 < i--) {
  s += url[random[i] & urlLen]
}
pending…
all combined (comparison, modulo, len var, assign)
let i = len,
  s = ''
    
while (i--) {
  s = s + url[random[i] % urlLen]
}
pending…
combined comparison, len var, assign
let i = len,
  s = ''
    
while (i--) {
  s = s + url[random[i] & urlLen]
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments