CARVIEW |
Select Language
HTTP/2 200
date: Sat, 09 Aug 2025 12:31:04 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-repository-download: git clone https://github.com/golang/go.git
etag: W/"9706d9d748f4389b5ce2ace2fa6ef678"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=rcMmWb9U76LbuzP7q35rLkN%2BOffHXG%2FmyhJ8%2BPLtMvbxtwr7KcLrHvisKpkS%2BxmtdHKRxmZh5dcSvdUPOtBhcUxTXwYSu%2BVK%2BYq5snukqJudjbBBNj5Se9MFXTZLhKZdwKaHT3iibJIp7%2FGJqJkpurmNlhjCkO9lLeaHhRO06gaOe8hhKtZ0aZqX7M9dvs4yYt4wFspTORbVV1q4RdKJbRjSrvcTpdDJHSKY8IrlrNBdCJs5M8pDxqvAzVm0fdHP9aanSjHQAWRI1OfC8u%2BuXA%3D%3D--uqeOcNQ3jd14Ioe3--LlwzFTtC9APCetR5qogZIw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1796604594.1754742663; Path=/; Domain=github.com; Expires=Sun, 09 Aug 2026 12:31:03 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 09 Aug 2026 12:31:03 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: C040:246B3D:1DE6D7:25E385:68973F87
time: optimize time <-> date conversions · golang/go@c5de950 · GitHub
Copy file name to clipboard
Copy file name to clipboard
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Commit c5de950
committed
time: optimize time <-> date conversions
Optimize the time -> date and date -> time conversions using the
methods outlined in:
Cassio Neri and Lorenz Schneider,
“Euclidean affine functions and their
application to calendar algorithms,”
SP&E 2023. https://doi.org/10.1002/spe.3172
I took the opportunity to introduce some types to make the code
significantly clearer and optimize a few other parts I noticed along
the way. The result is noticeably faster across the board.
Probably this doesn't matter much in real programs, but all the other
languages are picking this up, and it is less code than what we had
before.
Proposal #63844 suggested adopting this algorithm and simultaneously
restricting the range of valid years supported by the package from its
current ±292277022399 (plenty for anyone) to a mere ±32767.
This CL does NOT make any such restriction. The range of valid years
is almost exactly what it was before. (It is the same size but shifted
10 months earlier, which no one will ever care about.)
This CL removes any real need to consider the proposal, since it
would be a breaking change for truly insignificant benefit.
Thanks to Normandes Junior and Cassio Neri for CL 548155
and for discussion on #63844, which prompted me to write this CL.
This CL is all new code and does not include code from CL 548155
except as noted in the isLeap function implementation.
For #63844.
goos: linux
goarch: amd64
pkg: time
cpu: AMD Ryzen 9 7950X 16-Core Processor
│ timeold.txt │ timenew.txt │
│ sec/op │ sec/op vs base │
Format-32 156.5n ± 1% 148.1n ± 1% -5.37% (n=125)
FormatRFC3339-32 118.5n ± 1% 112.1n ± 1% -5.40% (n=125)
FormatRFC3339Nano-32 119.2n ± 1% 113.0n ± 1% -5.20% (n=125)
FormatNow-32 96.88n ± 2% 97.22n ± 1% ~ (p=0.173 n=125)
MarshalJSON-32 79.77n ± 1% 75.82n ± 1% -4.95% (n=125)
MarshalText-32 79.25n ± 1% 76.18n ± 1% -3.87% (p=0.000 n=125)
Parse-32 79.80n ± 1% 78.28n ± 1% -1.90% (p=0.000 n=125)
ParseRFC3339UTC-32 29.10n ± 1% 28.90n ± 0% ~ (p=0.094 n=125)
ParseRFC3339UTCBytes-32 30.72n ± 1% 30.88n ± 1% ~ (p=0.894 n=125)
ParseRFC3339TZ-32 92.29n ± 0% 90.27n ± 1% -2.19% (p=0.000 n=125)
ParseRFC3339TZBytes-32 133.4n ± 1% 132.0n ± 1% ~ (p=0.004 n=125)
ParseDuration-32 41.11n ± 3% 44.08n ± 2% ~ (p=0.088 n=125)
Hour-32 2.834n ± 0% 2.829n ± 1% ~ (p=0.891 n=125)
Second-32 2.811n ± 1% 2.828n ± 1% ~ (p=0.208 n=125)
Date-32 9.228n ± 1% 5.788n ± 0% -37.28% (n=125)
Year-32 6.404n ± 1% 4.673n ± 1% -27.03% (n=125)
YearDay-32 6.399n ± 1% 5.802n ± 0% -9.33% (n=125)
Month-32 9.108n ± 1% 4.700n ± 1% -48.40% (n=125)
Day-32 9.106n ± 1% 4.686n ± 1% -48.54% (n=125)
ISOWeek-32 10.060n ± 0% 7.998n ± 1% -20.50% (n=125)
GoString-32 84.59n ± 1% 83.82n ± 1% ~ (p=0.027 n=125)
DateFunc-32 6.993n ± 0% 6.144n ± 1% -12.14% (n=125)
UnmarshalText-32 94.78n ± 2% 89.49n ± 1% -5.58% (n=125)
geomean 29.60n 26.13n -11.70%
goos: darwin
goarch: arm64
pkg: time
cpu: Apple M3 Pro
│ timeold-m3.txt │ timenew-m3.txt │
│ sec/op │ sec/op vs base │
Format-12 152.6n ± 0% 147.4n ± 0% -3.41% (n=125)
FormatRFC3339-12 101.50n ± 0% 92.02n ± 0% -9.34% (n=125)
FormatRFC3339Nano-12 101.30n ± 0% 92.68n ± 0% -8.51% (n=125)
FormatNow-12 93.50n ± 0% 94.65n ± 0% +1.23% (p=0.000 n=125)
MarshalJSON-12 50.06n ± 0% 48.25n ± 0% -3.62% (n=125)
MarshalText-12 49.70n ± 0% 47.51n ± 0% -4.41% (n=125)
Parse-12 97.91n ± 0% 95.90n ± 0% -2.05% (n=125)
ParseRFC3339UTC-12 36.45n ± 0% 35.78n ± 1% -1.84% (n=125)
ParseRFC3339UTCBytes-12 38.11n ± 0% 37.42n ± 0% -1.81% (n=125)
ParseRFC3339TZ-12 100.80n ± 1% 97.58n ± 0% -3.19% (n=125)
ParseRFC3339TZBytes-12 111.8n ± 1% 107.4n ± 0% -3.94% (n=125)
ParseDuration-12 52.70n ± 0% 52.84n ± 0% ~ (p=0.028 n=125)
Hour-12 2.657n ± 0% 2.655n ± 0% ~ (p=0.018 n=125)
Second-12 2.656n ± 0% 2.654n ± 0% ~ (p=0.084 n=125)
Date-12 8.201n ± 0% 5.055n ± 0% -38.36% (n=125)
Year-12 5.694n ± 0% 4.086n ± 0% -28.24% (n=125)
YearDay-12 5.693n ± 0% 4.828n ± 0% -15.19% (n=125)
Month-12 8.206n ± 0% 4.231n ± 0% -48.44% (n=125)
Day-12 8.199n ± 0% 4.551n ± 0% -44.49% (n=125)
ISOWeek-12 9.032n ± 0% 7.298n ± 0% -19.20% (n=125)
GoString-12 62.78n ± 0% 60.61n ± 0% -3.46% (n=125)
DateFunc-12 7.318n ± 0% 6.431n ± 0% -12.12% (n=125)
UnmarshalText-12 99.66n ± 0% 95.64n ± 0% -4.03% (n=125)
Change-Id: I089a072a731914702f8087018d00960e129f86b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/586257
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>1 parent 31e692b commit c5de950Copy full SHA for c5de950
File tree
Expand file treeCollapse file tree
7 files changed
+724
-278
lines changedFilter options
- src/time
Expand file treeCollapse file tree
7 files changed
+724
-278
lines changedsrc/time/abs_test.go
Copy file name to clipboard+183Lines changed: 183 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + |
+19-15Lines changed: 19 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
140 | 140 |
| |
141 | 141 |
| |
142 | 142 |
| |
143 |
| - | |
| 143 | + | |
144 | 144 |
| |
145 | 145 |
| |
146 | 146 |
| |
| |||
168 | 168 |
| |
169 | 169 |
| |
170 | 170 |
| |
171 |
| - | |
| 171 | + | |
| 172 | + | |
172 | 173 |
| |
173 | 174 |
| |
174 | 175 |
| |
| |||
574 | 575 |
| |
575 | 576 |
| |
576 | 577 |
| |
577 |
| - | |
578 |
| - | |
579 |
| - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
580 | 581 |
| |
581 | 582 |
| |
582 | 583 |
| |
| |||
664 | 665 |
| |
665 | 666 |
| |
666 | 667 |
| |
667 |
| - | |
668 |
| - | |
| 668 | + | |
| 669 | + | |
669 | 670 |
| |
| 671 | + | |
670 | 672 |
| |
671 | 673 |
| |
672 | 674 |
| |
673 |
| - | |
| 675 | + | |
674 | 676 |
| |
675 | 677 |
| |
676 | 678 |
| |
| |||
689 | 691 |
| |
690 | 692 |
| |
691 | 693 |
| |
692 |
| - | |
693 |
| - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
694 | 698 |
| |
695 | 699 |
| |
696 | 700 |
| |
697 | 701 |
| |
698 |
| - | |
| 702 | + | |
699 | 703 |
| |
700 | 704 |
| |
701 | 705 |
| |
| |||
717 | 721 |
| |
718 | 722 |
| |
719 | 723 |
| |
720 |
| - | |
| 724 | + | |
721 | 725 |
| |
722 |
| - | |
| 726 | + | |
723 | 727 |
| |
724 | 728 |
| |
725 | 729 |
| |
| |||
1350 | 1354 |
| |
1351 | 1355 |
| |
1352 | 1356 |
| |
1353 |
| - | |
| 1357 | + | |
1354 | 1358 |
| |
1355 | 1359 |
| |
1356 |
| - | |
| 1360 | + | |
1357 | 1361 |
| |
1358 | 1362 |
| |
1359 | 1363 |
| |
|
+2-2Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
22 |
| - | |
| 22 | + | |
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
32 |
| - | |
| 32 | + | |
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
|
src/time/linkname_test.go
Copy file name to clipboard+41Lines changed: 41 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + |
You can’t perform that action at this time.
0 commit comments