log vs division

Benchmark created on


Description

Test what algorithm is better for finding out number of digits in number.

Setup

var log10 = Math.log(10);

Test runner

Ready to run.

Testing in
TestOps/sec
log
var num = Math.random * 1e100;

var digits = Math.floor(Math.log(num) / log10) + 1;
ready
division
var num = Math.random * 1e100;

for(var i = 0; num > 1; i++) {
    num /= 10;
}

var digits = i;
ready

Revisions

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