-
Notifications
You must be signed in to change notification settings - Fork 324
Open
Description
我做了一下压力测试,感觉效率上有改进的余地:
describe('求余数运算', () => {
//Math.round 用时14ms
it('test Math', () => {
let total=0;
for (let i = 1; i <= 10000 * 10; i++) {
total += Math.round(i * 100) / 100;
}
console.log(total);
});
//Math.round 再加上求精度,转浮点数,用时 273ms
it('test Math2', () => {
let total=0;
for (let i = 1; i <= 10000 * 10; i++) {
total += Math.round(parseFloat((i * 100).toPrecision(14))) / 100;
}
console.log(total);
});
//NP.round 用时1sec963ms
it('test NP', () => {
let total=0;
for (let i = 1; i <= 10000 * 10; i++) {
total += NP.round(i ,2) ;
}
console.log(total);
});
})
Metadata
Metadata
Assignees
Labels
No labels