github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/session/mbtime/mbtime_test.go (about) 1 /* 2 * Copyright (C) 2020 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package mbtime 19 20 import ( 21 "testing" 22 "time" 23 ) 24 25 func TestNow(t *testing.T) { 26 for i := 0; i < 100; i++ { 27 t1 := Now() 28 t2 := Now() 29 if t1.Nano() > t2.Nano() { 30 t.Fatalf("t1=%d should have been less than or equal to t2=%d", t1, t2) 31 } 32 } 33 } 34 35 func TestSince(t *testing.T) { 36 for i := 0; i < 100; i++ { 37 ts := Now() 38 d := Since(ts) 39 if d < 0 { 40 t.Fatalf("d=%d should be greater than or equal to zero", d) 41 } 42 } 43 } 44 45 func BenchmarkNow(b *testing.B) { 46 for i := 0; i < b.N; i++ { 47 _ = Now() 48 } 49 } 50 51 func BenchmarkStdNow(b *testing.B) { 52 for i := 0; i < b.N; i++ { 53 _ = time.Now() 54 } 55 } 56 57 func BenchmarkSince(b *testing.B) { 58 for i := 0; i < b.N; i++ { 59 ts := Now() 60 Since(ts) 61 } 62 } 63 64 func BenchmarkStdSince(b *testing.B) { 65 for i := 0; i < b.N; i++ { 66 ts := time.Now() 67 time.Since(ts) 68 } 69 }