Skip to content

Avoid Date object creation.#22

Closed
kitschpatrol wants to merge 1 commit into
tweakpane:mainfrom
kitschpatrol:date-performance
Closed

Avoid Date object creation.#22
kitschpatrol wants to merge 1 commit into
tweakpane:mainfrom
kitschpatrol:date-performance

Conversation

@kitschpatrol
Copy link
Copy Markdown
Contributor

@kitschpatrol kitschpatrol commented Dec 18, 2023

Very minor (20–30%) performance improvements by avoiding new Date() in fps-graph.ts and cubic-bezier-preview.ts.

const iterations = 10_000_000;

console.time("new Date().getTime()");
for (let i = 0; i < iterations; i++) {
  const t = new Date().getTime();
}
console.timeEnd("new Date().getTime()");

console.time("Date.now()");
for (let i = 0; i < iterations; i++) {
  const t = Date.now();
}
console.timeEnd("Date.now()");

// new Date().getTime(): 399.740966796875 ms
// Date.now(): 276.43994140625 ms

Just noticed it while working on #21.

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.

1 participant