nv-string-pos-int-lt1e21
v1.0.2
Published
nv-string-pos-int-lt1e21 ======================= - same as Number.toString() - but only work WHEN number is integer AND number >0 AND number < 1e21 - slightly faster than built-in .toString()
Downloads
3
Readme
nv-string-pos-int-lt1e21
- same as Number.toString()
- but only work WHEN number is integer AND number >0 AND number < 1e21
- slightly faster than built-in .toString()
install
- npm install nv-string-pos-int-lt1e21
usage
const {pos_i2s_if_gt0_and_lt_1e21 } = require("nv-string-pos-int-lt1e21");
example
const rand_int = ()=>require("nv-random-number").int(1,2**53);
// random samples for test
const narr = [];
const sarr = [];
for(let i=0;i<1000000;++i) {
let int = rand_int();
let s = int.toString();
narr.push(int);
sarr.push(s);
}
const {pos_i2s_if_gt0_and_lt_1e21} = require("../index");
var S;
//assert
for(let i=0; i<1000000;++i) {
let n = narr[i]
let s = pos_i2s_if_gt0_and_lt_1e21(n);
if(s!==sarr[i]) {
console.log(sarr[i],n,s)
}
}
////
const f0 = ()=> {
for(let i=0; i<1000000;++i) {
let n = narr[i]
S = n.toString();
}
}
const f1 = ()=> {
for(let i=0; i<1000000;++i) {
let n = narr[i]
S = pos_i2s_if_gt0_and_lt_1e21(n)
}
}
const {sync} = require("nv-facutil-simple-test")
console.log(sync(10,f0));
console.log(sync(10,f1));
{ rounds: 10, f: [Function: f0], costed: 2530.5817646980286 }
{ rounds: 10, f: [Function: f1], costed: 1408.7329750061035 }
METHODS
APIS
LICENSE
- ISC