Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(current time): replace Date.now to performance.now #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

behnammodi
Copy link
Contributor

@behnammodi behnammodi commented Apr 5, 2021

As you know performance.now() is the best way to measure or compare time. However, I use Date.now() as a fallback when performance.now() is not available.

@behnammodi
Copy link
Contributor Author

@aFarkas Could you please review this PR, and if everything ok publish it on npm


const getCurrentTime = typeof performance === 'object' && typeof performance.now === 'function'
? () => performance.now()
: () => Date.now();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this work without the arrow functions?

  ? performance.now
  : Date.now;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works, but I added the arrow function to prevent redundant calling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants