Comments (8)
In this case specifically I'm using performance.now()
to compare the deltatime between two "wheel"
events in order to determine how long the user has been scrolling. But I have also used performance.now()
a lot in the past when computing the deltatime between two frames, or animating an object over time for example.
Aside from the higher precision, performance.now()
is also more beneficial in these cases because these systems could get messed up when the system time changes.
from deno_std.
perfomance.now()
doesn't return unix timestamp, but it returns elapsed time from some random time origin. If FakeTime
works with perfomance.now()
in a similar way as Deno.now
, that feels confusing to me.
Also higher precision time is disabled by default, and its usage is generally discouraged because of the security issues. I think there's no particular reason to encourage the use of performance.now()
from deno_std.
As for discouraging/encouraging the use of
performance.now()
, it really depends on what you plan on using it for. MDN puts it best:Also,
Date.now()
may have been impacted by system and user clock adjustments, clock skew, etc. as it is relative to the Unix epoch (1970-01-01T00:00:00Z) and dependent on the system clock. Theperformance.now()
method on the other hand is relative to thetimeOrigin
property which is a monotonic clock: its current time never decreases and isn't subject to adjustments.
If the point of performance.now()
is being independent of system time, then I wonder if it's good idea to let FakeTime affect performance.now()
as FakeTime simulates 'system time'
from deno_std.
Are you able to elaborate on your use case?
from deno_std.
My use case is that I'm using performance.now()
in many places instead of Date.now()
. I'm not really sure why to be honest, I think it's an old relic from when performance.now()
used to have higher precision than Date.now()
.
I was trying to write tests for code that was using performance.now()
and planned on using FakeTime
, thinking it would mock it. But that's when I found out it wasn't added yet.
from deno_std.
Let's consider your use case. Is its purpose to measure durations between multiple points in time? Does it need the higher precision of performance.now()
? If the answer to both of these questions is yes, using performance.now()
makes sense. If the answer to both is now, Date.now()
, which already has the mocking utility, it makes more sense to use. I just want to ensure that the use case for mocking performance.now()
is valid enough to justify having the mocking utility for it.
from deno_std.
Ok. That sounds reasonable to me. @kt3k, WDYT? I misunderstood. I agree with Yoshiya's comment below.
from deno_std.
I looked some more into this and it seems like the precision of performance.now()
is 100 microseconds nowadays. Which is still one order of magnitude more precise than Date.now()
.
As for discouraging/encouraging the use of performance.now()
, it really depends on what you plan on using it for.
MDN puts it best:
Also,
Date.now()
may have been impacted by system and user clock adjustments, clock skew, etc. as it is relative to the Unix epoch (1970-01-01T00:00:00Z) and dependent on the system clock. Theperformance.now()
method on the other hand is relative to thetimeOrigin
property which is a monotonic clock: its current time never decreases and isn't subject to adjustments.
FakeTime
seems to suggest it affects all time related apis, including setTimeout
, setInterval
etc. So it was kind of surprising to me that performance.now()
remained unaffected.
Although I agree including performance.now()
might feel somewhat confusing. With most FakeTime
methods I think it should be pretty clear. FakeTime.tick()
for instance would move time forward for both Date.now()
and performance.now()
. The only two instances that seem confusing are getting/setting FakeTime.now
and FakeTime.start
, since these specifically seem related to system time.
from deno_std.
Related Issues (20)
- suggestion: generate package dependency tree image
- stabilize `@std/crypto`
- proposal: shorten the waiting period to 3 weeks after July
- to-do: investigate the viability of `formatter` option for `assertEquals()` HOT 1
- suggestion: factor out optional arguments into options object for `assertRejects()`, `assertThrows()` and `aasertIsError()` HOT 7
- casing inconsistency in varint APIs HOT 2
- `UInt` casing in `MaxUInt64` is inconsistent with Web Standard APIs HOT 1
- issue: `decodeBase32()` throws when length is not a multiple of 8 HOT 1
- issue: `decodeBase32()` throws on bad padding length HOT 2
- stop doing deprecation process for 0.x version packages
- suggestion: stabilize `KeyStack` HOT 3
- suggestion: remove `GlobToRegExpOptions.osType` HOT 1
- suggestion: add signed cookie example
- suggestion: make `isWindows` cross-runtime in `@std/path`
- suggestion: add base32hex to encoding
- stabilize `@std/html`
- stabilize `@std/path`
- stabilize `@std/toml`
- stabilize `@std/url`
- Snapshot testing generation is non-deterministic/broken since 1.37.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deno_std.