(b *testing.B)
| 11 | ) |
| 12 | |
| 13 | func BenchmarkMergeSlicesParallel(b *testing.B) { |
| 14 | testCases := []struct { |
| 15 | inputSize int |
| 16 | stringsPerInput int |
| 17 | duplicateRatio float64 |
| 18 | }{ |
| 19 | { |
| 20 | inputSize: 100, |
| 21 | stringsPerInput: 100, |
| 22 | duplicateRatio: 0.3, // Deduped array size will be 70% of the total of the input |
| 23 | }, |
| 24 | { |
| 25 | inputSize: 100, |
| 26 | stringsPerInput: 100, |
| 27 | duplicateRatio: 0.8, // Deduped array size will be 20% of the total of the input |
| 28 | }, |
| 29 | { |
| 30 | inputSize: 100, |
| 31 | stringsPerInput: 100, |
| 32 | duplicateRatio: 0.95, // Deduped array size will be 5% of the total of the input |
| 33 | }, |
| 34 | { |
| 35 | inputSize: 150, |
| 36 | stringsPerInput: 300, |
| 37 | duplicateRatio: 0.3, |
| 38 | }, |
| 39 | { |
| 40 | inputSize: 150, |
| 41 | stringsPerInput: 300, |
| 42 | duplicateRatio: 0.8, |
| 43 | }, |
| 44 | { |
| 45 | inputSize: 150, |
| 46 | stringsPerInput: 300, |
| 47 | duplicateRatio: 0.95, |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | randomStrings := GenerateRandomStrings() |
| 52 | type ParallelismType int |
| 53 | |
| 54 | const ( |
| 55 | usingMap ParallelismType = iota |
| 56 | ) |
| 57 | |
| 58 | parallelism := []ParallelismType{usingMap, 1, 8} |
| 59 | |
| 60 | for _, tc := range testCases { |
| 61 | input := make([][]string, tc.inputSize) |
| 62 | unusedStrings := make([]string, min(len(randomStrings), tc.inputSize*tc.stringsPerInput)) |
| 63 | usedStrings := make([]string, 0, len(unusedStrings)) |
| 64 | copy(unusedStrings, randomStrings) |
| 65 | |
| 66 | for i := 0; i < tc.inputSize; i++ { |
| 67 | stringsToBeReused := make([]string, len(usedStrings)) |
| 68 | copy(stringsToBeReused, usedStrings) |
| 69 | for j := 0; j < tc.stringsPerInput; j++ { |
| 70 | // Get a random string already used |
nothing calls this directly
no test coverage detected