-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use third-party library to convert time.Time to UTC string
- Loading branch information
1 parent
5cd13fc
commit 134c6d7
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// go test -v -cpu=4 -run=none -bench=. -benchmem strftime_test.go | ||
package strftime_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/phuslu/fasttime" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var now = time.Now().UTC() | ||
|
||
func TestEquivalence(t *testing.T) { | ||
std1 := now.Format(time.RFC3339Nano) | ||
std2 := now.Format("2006-01-02T15:04:05.999999999Z") | ||
fast := fasttime.Strftime("%Y-%m-%dT%H:%M:%S.%N%:z", now) | ||
require.Equal(t, std1, fast) | ||
require.Equal(t, std2, fast) | ||
} | ||
|
||
func BenchmarkRFC3339StdTime(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
now.Format(time.RFC3339Nano) | ||
} | ||
} | ||
|
||
func BenchmarkRFC3339Fasttime(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
fasttime.Strftime("%Y-%m-%dT%H:%M:%S%N:z", now) | ||
} | ||
} |