Eyad Syria-lover Posted September 13, 2016 Share Posted September 13, 2016 I Have Just Read About The performance.now() Standard,But I Felt Uncomfortable About It. Is There Any Other Way To Solve This?. Link to comment Share on other sites More sharing options...
Ingolme Posted September 13, 2016 Share Posted September 13, 2016 If you care about compatibility with older browsers, you can use Date() objects. It has millisecond precision, but you can benchmark code by running it thousands of times. var iterations = 100000; var start = (new Date()).getTime(); for(var i = 0; i < iterations; i++) { // Put code here for benchmarking } var end = (new Date()).getTime(); // Find out how long it took var elapsedTime = end - start; // Find out how much time passes for just one function call var averageTime = elapsedTime / iterations; // Output data console.log(averageTime); Link to comment Share on other sites More sharing options...
justsomeguy Posted September 13, 2016 Share Posted September 13, 2016 But I Felt Uncomfortable About It.What does that mean? What about it makes you feel uncomfortable? Link to comment Share on other sites More sharing options...
Eyad Syria-lover Posted September 14, 2016 Author Share Posted September 14, 2016 What does that mean? What about it makes you feel uncomfortable? It's Returning So Many Numbers After Decimal... Like This: 10.925054550170898 Link to comment Share on other sites More sharing options...
Eyad Syria-lover Posted September 14, 2016 Author Share Posted September 14, 2016 If you care about compatibility with older browsers, you can use Date() objects. It has millisecond precision, but you can benchmark code by running it thousands of times. var iterations = 100000; var start = (new Date()).getTime(); for(var i = 0; i < iterations; i++) { // Put code here for benchmarking } var end = (new Date()).getTime(); // Find out how long it took var elapsedTime = end - start; // Find out how much time passes for just one function call var averageTime = elapsedTime / iterations; // Output data console.log(averageTime); This Is Taking More Than Expected Because The Iteration Is Very Big,Do You Have Another Way Sir? Link to comment Share on other sites More sharing options...
Ingolme Posted September 14, 2016 Share Posted September 14, 2016 Reduce the number of iterations. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 14, 2016 Share Posted September 14, 2016 It's Returning So Many Numbers After Decimal...So, what's the problem? Most floating-point numbers in Javascript aren't going to be precise after a few decimals, so if the precision of that is supposed to be to 3 decimal places then you can drop the other digits. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now