Patashu / break_eternity.js

A Javascript numerical library to represent numbers as large as 10^^1e308 and as small as 10^-10^^1e308. Sequel to break_infinity.js, designed for incremental games.
MIT License
121 stars 44 forks source link

Use Decimal.fromX instead of constructor / D when possible #90

Closed mcpower closed 2 years ago

mcpower commented 2 years ago

For some reason the constructor is noticeably slower than fromX:

Patashu commented 2 years ago

I can't reproduce 'constructor is 85% slower than fromDecimal', they're equal within margin of error for me. And constructor is less than 10% slower than fromNumber.

But logically it makes absolute sense that it's quicker to say 'hey this is an X' than to make the constructor do checks and call an extra function, so I'll probably merge this anyway after checking it over.

James103 commented 2 years ago

I can't reproduce 'constructor is 85% slower than fromDecimal', they're equal within margin of error for me

The difference is there for me, but it's only a few percent.

mcpower commented 2 years ago

Hm, I can't reproduce it either - maybe there's been some V8 optimisations since I wrote my PR.