@@ -292,10 +292,7 @@ func hitRateTinyLFU(keys []int, cacheSize int) float64 {
292292}
293293
294294func hitRateFreecache (keys []int , cacheSize int ) float64 {
295- cacheBytes := cacheSize * 24
296- if cacheBytes < 512 * 1024 {
297- cacheBytes = 512 * 1024
298- }
295+ cacheBytes := max (cacheSize * 24 , 512 * 1024 )
299296 cache := freecache .NewCache (cacheBytes )
300297 // Pre-compute keys and values to avoid conversion overhead affecting hit rate measurement
301298 precomputedKeys := make ([][]byte , hitRateKeySpace )
@@ -755,9 +752,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
755752 cache .Set (i , i )
756753 }
757754 for range threads {
758- wg .Add (1 )
759- go func () {
760- defer wg .Done ()
755+ wg .Go (func () {
761756 for i := 0 ; ; {
762757 for range opsBatchSize {
763758 key := keys [i % workloadLen ]
@@ -773,7 +768,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
773768 return
774769 }
775770 }
776- }( )
771+ })
777772 }
778773
779774 case "otter" :
@@ -782,9 +777,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
782777 cache .Set (i , i )
783778 }
784779 for range threads {
785- wg .Add (1 )
786- go func () {
787- defer wg .Done ()
780+ wg .Go (func () {
788781 for i := 0 ; ; {
789782 for range opsBatchSize {
790783 key := keys [i % workloadLen ]
@@ -800,7 +793,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
800793 return
801794 }
802795 }
803- }( )
796+ })
804797 }
805798
806799 case "ristretto" :
@@ -814,9 +807,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
814807 }
815808 ristrettoCache .Wait ()
816809 for range threads {
817- wg .Add (1 )
818- go func () {
819- defer wg .Done ()
810+ wg .Go (func () {
820811 for i := 0 ; ; {
821812 for range opsBatchSize {
822813 key := keys [i % workloadLen ]
@@ -832,7 +823,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
832823 return
833824 }
834825 }
835- }( )
826+ })
836827 }
837828
838829 case "lru" :
@@ -841,9 +832,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
841832 cache .Add (i , i )
842833 }
843834 for range threads {
844- wg .Add (1 )
845- go func () {
846- defer wg .Done ()
835+ wg .Go (func () {
847836 for i := 0 ; ; {
848837 for range opsBatchSize {
849838 key := keys [i % workloadLen ]
@@ -859,7 +848,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
859848 return
860849 }
861850 }
862- }( )
851+ })
863852 }
864853
865854 case "tinylfu" :
@@ -870,9 +859,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
870859 cache .Set (& tinylfu.Item {Key : keysAsStrings [i ], Value : i })
871860 }
872861 for range threads {
873- wg .Add (1 )
874- go func () {
875- defer wg .Done ()
862+ wg .Go (func () {
876863 for i := 0 ; ; {
877864 for range opsBatchSize {
878865 key := keys [i % workloadLen ]
@@ -888,7 +875,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
888875 return
889876 }
890877 }
891- }( )
878+ })
892879 }
893880
894881 case "freecache" :
@@ -902,9 +889,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
902889 cache .Set (keysAsBytes [i ], vals [i ], 0 )
903890 }
904891 for range threads {
905- wg .Add (1 )
906- go func () {
907- defer wg .Done ()
892+ wg .Go (func () {
908893 for i := 0 ; ; {
909894 for range opsBatchSize {
910895 key := keys [i % workloadLen ]
@@ -920,7 +905,7 @@ func measureZipfQPS(cacheName string, threads int, keys []int) float64 {
920905 return
921906 }
922907 }
923- }( )
908+ })
924909 }
925910 }
926911
0 commit comments