|
6 | 6 |
|
7 | 7 | "github.com/stretchr/testify/require" |
8 | 8 | "github.com/tuneinsight/lattigo/v6/utils/bignum" |
| 9 | + "github.com/tuneinsight/lattigo/v6/utils/sampling" |
9 | 10 | ) |
10 | 11 |
|
11 | 12 | func BenchmarkRing(b *testing.B) { |
@@ -88,6 +89,108 @@ func benchSampling(tc *testParams, b *testing.B) { |
88 | 89 | sampler.Read(pol) |
89 | 90 | } |
90 | 91 | }) |
| 92 | + b.Run(testString("Sampling/ThreadSafePRNGNaive/Gaussian", tc.ringQ), func(b *testing.B) { |
| 93 | + |
| 94 | + prng := &sampling.ThreadSafePRNGNaive{} |
| 95 | + sampler, err := NewSampler(prng, tc.ringQ, DiscreteGaussian{Sigma: DefaultSigma, Bound: DefaultBound}, false) |
| 96 | + require.NoError(b, err) |
| 97 | + |
| 98 | + b.RunParallel(func(pb *testing.PB) { |
| 99 | + for pb.Next() { |
| 100 | + sampler.Read(pol) |
| 101 | + } |
| 102 | + }) |
| 103 | + }) |
| 104 | + b.Run(testString("Sampling/ThreadSafeShallowCopy/Gaussian", tc.ringQ), func(b *testing.B) { |
| 105 | + |
| 106 | + b.RunParallel(func(pb *testing.PB) { |
| 107 | + prng, _ := sampling.NewPRNG() |
| 108 | + sampler, _ := NewSampler(prng, tc.ringQ, DiscreteGaussian{Sigma: DefaultSigma, Bound: DefaultBound}, false) |
| 109 | + for pb.Next() { |
| 110 | + sampler.Read(pol) |
| 111 | + } |
| 112 | + }) |
| 113 | + }) |
| 114 | + b.Run(testString("Sampling/ThreadSafePRNG/Gaussian", tc.ringQ), func(b *testing.B) { |
| 115 | + |
| 116 | + prng, err := sampling.NewThreadSafePRNG() |
| 117 | + sampler, err := NewSampler(prng, tc.ringQ, DiscreteGaussian{Sigma: DefaultSigma, Bound: DefaultBound}, false) |
| 118 | + require.NoError(b, err) |
| 119 | + |
| 120 | + b.RunParallel(func(pb *testing.PB) { |
| 121 | + for pb.Next() { |
| 122 | + sampler.Read(pol) |
| 123 | + } |
| 124 | + }) |
| 125 | + }) |
| 126 | + b.Run(testString("Sampling/ThreadSafePRNGNaive/Uniform", tc.ringQ), func(b *testing.B) { |
| 127 | + |
| 128 | + prng := &sampling.ThreadSafePRNGNaive{} |
| 129 | + sampler, err := NewSampler(prng, tc.ringQ, Uniform{}, true) |
| 130 | + require.NoError(b, err) |
| 131 | + |
| 132 | + b.RunParallel(func(pb *testing.PB) { |
| 133 | + for pb.Next() { |
| 134 | + sampler.Read(pol) |
| 135 | + } |
| 136 | + }) |
| 137 | + }) |
| 138 | + b.Run(testString("Sampling/ThreadSafeShallowCopy/Uniform", tc.ringQ), func(b *testing.B) { |
| 139 | + |
| 140 | + b.RunParallel(func(pb *testing.PB) { |
| 141 | + prng, _ := sampling.NewPRNG() |
| 142 | + sampler, _ := NewSampler(prng, tc.ringQ, Uniform{}, true) |
| 143 | + for pb.Next() { |
| 144 | + sampler.Read(pol) |
| 145 | + } |
| 146 | + }) |
| 147 | + }) |
| 148 | + b.Run(testString("Sampling/ThreadSafePRNG/Uniform", tc.ringQ), func(b *testing.B) { |
| 149 | + |
| 150 | + prng, err := sampling.NewThreadSafePRNG() |
| 151 | + sampler, err := NewSampler(prng, tc.ringQ, Uniform{}, true) |
| 152 | + require.NoError(b, err) |
| 153 | + |
| 154 | + b.RunParallel(func(pb *testing.PB) { |
| 155 | + for pb.Next() { |
| 156 | + sampler.Read(pol) |
| 157 | + } |
| 158 | + }) |
| 159 | + }) |
| 160 | + b.Run(testString("Sampling/ThreadSafePRNGNaive/Ternary/0.3", tc.ringQ), func(b *testing.B) { |
| 161 | + |
| 162 | + prng := &sampling.ThreadSafePRNGNaive{} |
| 163 | + sampler, err := NewSampler(prng, tc.ringQ, Ternary{P: 1.0 / 3}, true) |
| 164 | + require.NoError(b, err) |
| 165 | + |
| 166 | + b.RunParallel(func(pb *testing.PB) { |
| 167 | + for pb.Next() { |
| 168 | + sampler.Read(pol) |
| 169 | + } |
| 170 | + }) |
| 171 | + }) |
| 172 | + b.Run(testString("Sampling/ThreadSafeShallowCopy/Ternary/0.3", tc.ringQ), func(b *testing.B) { |
| 173 | + |
| 174 | + b.RunParallel(func(pb *testing.PB) { |
| 175 | + prng, _ := sampling.NewPRNG() |
| 176 | + sampler, _ := NewSampler(prng, tc.ringQ, Ternary{P: 1.0 / 3}, true) |
| 177 | + for pb.Next() { |
| 178 | + sampler.Read(pol) |
| 179 | + } |
| 180 | + }) |
| 181 | + }) |
| 182 | + b.Run(testString("Sampling/ThreadSafePRNG/Ternary/0.3", tc.ringQ), func(b *testing.B) { |
| 183 | + |
| 184 | + prng, err := sampling.NewThreadSafePRNG() |
| 185 | + sampler, err := NewSampler(prng, tc.ringQ, Ternary{P: 1.0 / 3}, true) |
| 186 | + require.NoError(b, err) |
| 187 | + |
| 188 | + b.RunParallel(func(pb *testing.PB) { |
| 189 | + for pb.Next() { |
| 190 | + sampler.Read(pol) |
| 191 | + } |
| 192 | + }) |
| 193 | + }) |
91 | 194 |
|
92 | 195 | b.Run(testString("Sampling/Ternary/0.3", tc.ringQ), func(b *testing.B) { |
93 | 196 |
|
|
0 commit comments