Skip to content

fix: optimize dayOfWeek & dateFromEpoch routines in date#3033

Merged
MaxGraey merged 4 commits into
AssemblyScript:mainfrom
MaxGraey:date-perf
Jul 21, 2026
Merged

fix: optimize dayOfWeek & dateFromEpoch routines in date#3033
MaxGraey merged 4 commits into
AssemblyScript:mainfrom
MaxGraey:date-perf

Conversation

@MaxGraey

@MaxGraey MaxGraey commented Jul 8, 2026

Copy link
Copy Markdown
Member
floorDiv(year, 400)  ->  floorDiv(floorDiv(year, 100), 4) 

Since arithmetic shift year >> 2 is equal to floorDiv(year, 4):

century = floorDiv(year, 100)
floorDiv(century, 4)  ->  century >> 2

And full simplifcation:

floorDiv(year, 4) - floorDiv(year, 100) + floorDiv(year, 400)

->

(year >> 2) - century + (century >> 2)

Also added couple of tests

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

Comment thread std/assembly/date.ts Outdated
@MaxGraey MaxGraey changed the title fix: speedup dayOfWeek routine in date fix: optimize dayOfWeek & dateFromEpoch routines in date Jul 9, 2026
@MaxGraey
MaxGraey merged commit 9ca63f2 into AssemblyScript:main Jul 21, 2026
15 checks passed
@MaxGraey
MaxGraey deleted the date-perf branch July 21, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants