mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
BenchmarkGetCurrentTime-4 100000000 11.60 ns/op 0 B/op 0 allocs/op --> BenchmarkGetCurrentTime-4 895091701 1.31 ns/op 0 B/op 0 allocs/op Signed-off-by: slasher <mcq.sejust@gmail.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
// Copyright 2018 The CubeFS Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
// implied. See the License for the specific language governing
|
|
// permissions and limitations under the License.
|
|
|
|
package timeutil
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestGetCurrentTimeUnix(t *testing.T) {
|
|
t1 := GetCurrentTimeUnix()
|
|
t2 := GetCurrentTime().Unix()
|
|
n := time.Now().Unix()
|
|
if n-t1 > 1 || n-t2 > 1 {
|
|
t.Errorf("wrong time: %d %d %d", n, t1, t2)
|
|
}
|
|
|
|
time.Sleep(time.Second * 2)
|
|
t1 = GetCurrentTimeUnix()
|
|
t2 = GetCurrentTime().Unix()
|
|
n = time.Now().Unix()
|
|
if n-t1 > 1 || n-t2 > 1 {
|
|
t.Errorf("wrong time: %d %d %d", n, t1, t2)
|
|
}
|
|
}
|
|
|
|
func BenchmarkGetCurrentTimeUnix(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
GetCurrentTimeUnix()
|
|
}
|
|
}
|
|
|
|
func BenchmarkGetCurrentTime(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
GetCurrentTime()
|
|
}
|
|
}
|
|
|
|
func BenchmarkGetNowTimeUnix(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
time.Now().Unix()
|
|
}
|
|
}
|