gitlab.com/SiaPrime/SiaPrime@v1.4.1/modules/host/contractmanager/storagefoldershrink_bench_test.go (about) 1 package contractmanager 2 3 import ( 4 "testing" 5 ) 6 7 // BenchmarkUnsetManySectors checks that unsetting a bunch of sectors 8 // individually takes an acceptable amount of time. Millions should be possible 9 // in well under a second. 10 // 11 // My laptop is doing 10e6 in 1.2 seconds. This is on the edge of too slow, but 12 // overall it's close enough. 13 func BenchmarkUnsetManySectors(b *testing.B) { 14 // Create a uint64 that has all of the bits set. 15 base := uint64(0) 16 base-- 17 18 // Benchmark how long it takes to unset the bits. 19 for i := 0; i < b.N; i++ { 20 // Create a usage array with all bits set. 21 b.StopTimer() 22 usageArray := make([]uint64, 10e6) 23 for i := 0; i < len(usageArray); i++ { 24 usageArray[i] = base 25 } 26 b.StartTimer() 27 28 // Set all of the bits to zero. 29 for j := 0; j < len(usageArray); j++ { 30 // Set each bit to zero. 31 for k := 0; k < storageFolderGranularity; k++ { 32 usageElement := usageArray[j] 33 usageElementUpdated := usageElement & (^(1 << uint64(k))) 34 usageArray[j] = usageElementUpdated 35 } 36 } 37 } 38 }