LingxinMeng 9 months ago
parent
commit
2872a2a3a0
1 changed files with 24 additions and 0 deletions
  1. 24 0
      test/lock_test.go

+ 24 - 0
test/lock_test.go

@@ -0,0 +1,24 @@
+package test
+
+import (
+	"fmt"
+	"sync"
+	"testing"
+)
+
+var myLocker sync.Mutex
+
+func BenchmarkLock(b *testing.B) {
+	// 重置计时器,这样不会把初始化时间计入基准测试结果
+	b.ResetTimer()
+
+	// 运行基准测试代码
+	for i := 0; i < b.N; i++ {
+		// 调用需要测试的函数或代码块
+		MyFunction()
+	}
+}
+
+func MyFunction() {
+	fmt.Println("MyFunction")
+}