Created
June 11, 2021 04:55
-
-
Save likev/a8014b3a962fbf75fb70968ebf9a131c to your computer and use it in GitHub Desktop.
JavaScript Math function performance test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function performance_test(name, func, iterations=1E8){ | |
console.time(name); | |
for(var i = 0; i < iterations; i++ ){ | |
func(); | |
}; | |
console.timeEnd(name) | |
} | |
performance_test('sin', _=>{Math.sin(Math.random())}) | |
performance_test('cos', _=>{Math.cos(Math.random())}) | |
performance_test('tan', _=>{Math.tan(Math.random())}) | |
performance_test('asin', _=>{Math.asin(Math.random())}) | |
performance_test('acos', _=>{Math.acos(Math.random())}) | |
performance_test('atan', _=>{Math.atan(Math.random())}) | |
performance_test('sinh', _=>{Math.sinh(Math.random())}) | |
performance_test('cosh', _=>{Math.cosh(Math.random())}) | |
performance_test('tanh', _=>{Math.tanh(Math.random())}) | |
performance_test('asinh', _=>{Math.asinh(Math.random())}) | |
performance_test('acosh', _=>{Math.acosh(Math.random())}) | |
performance_test('atanh', _=>{Math.atanh(Math.random())}) | |
performance_test('log', _=>{Math.log(Math.random())}) | |
performance_test('exp', _=>{Math.exp(Math.random())}) | |
performance_test('abs', _=>{Math.abs(Math.random())}) | |
performance_test('pow', _=>{Math.pow(3.333, Math.random())}) | |
performance_test('random', _=>{Math.random()}) | |
performance_test('do-nothing', _=>0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment