mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	增加基准测试
This commit is contained in:
		@@ -138,12 +138,12 @@ func TestCache_GC(t *testing.T) {
 | 
				
			|||||||
func TestCache_GC2(t *testing.T) {
 | 
					func TestCache_GC2(t *testing.T) {
 | 
				
			||||||
	runtime.GOMAXPROCS(1)
 | 
						runtime.GOMAXPROCS(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cache1 := NewCache(NewPiecesOption(32))
 | 
						var cache1 = NewCache(NewPiecesOption(32))
 | 
				
			||||||
	for i := 0; i < 1_000_000; i++ {
 | 
						for i := 0; i < 1_000_000; i++ {
 | 
				
			||||||
		cache1.Write(strconv.Itoa(i), i, time.Now().Unix()+int64(rands.Int(0, 10)))
 | 
							cache1.Write(strconv.Itoa(i), i, time.Now().Unix()+int64(rands.Int(0, 10)))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cache2 := NewCache(NewPiecesOption(5))
 | 
						var cache2 = NewCache(NewPiecesOption(5))
 | 
				
			||||||
	for i := 0; i < 1_000_000; i++ {
 | 
						for i := 0; i < 1_000_000; i++ {
 | 
				
			||||||
		cache2.Write(strconv.Itoa(i), i, time.Now().Unix()+int64(rands.Int(0, 10)))
 | 
							cache2.Write(strconv.Itoa(i), i, time.Now().Unix()+int64(rands.Int(0, 10)))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -153,3 +153,21 @@ func TestCache_GC2(t *testing.T) {
 | 
				
			|||||||
		time.Sleep(1 * time.Second)
 | 
							time.Sleep(1 * time.Second)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func BenchmarkNewCache(b *testing.B) {
 | 
				
			||||||
 | 
						runtime.GOMAXPROCS(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var cache = NewCache(NewPiecesOption(128))
 | 
				
			||||||
 | 
						for i := 0; i < 2_000_000; i++ {
 | 
				
			||||||
 | 
							cache.Write(strconv.Itoa(i), i, time.Now().Unix()+int64(rands.Int(10, 100)))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						b.Log("start reading ...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						b.ResetTimer()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						b.RunParallel(func(pb *testing.PB) {
 | 
				
			||||||
 | 
							for pb.Next() {
 | 
				
			||||||
 | 
								cache.Read(strconv.Itoa(rands.Int(0, 999999)))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user