Times how long each of the following takes: * Parsing and resolving from source * Encoding the APIs * Decoding the APIs * Decompressing the encoded data with various compressors.
(b *testing.B)
| 163 | // * Decoding the APIs |
| 164 | // * Decompressing the encoded data with various compressors. |
| 165 | func BenchmarkApproaches(b *testing.B) { |
| 166 | ctx := log.Testing(b) |
| 167 | |
| 168 | var apis []*semantic.API |
| 169 | var mappings *semantic.Mappings |
| 170 | |
| 171 | // Time how long it takes to parse and resolve the APIs from source |
| 172 | b.Run("Parse & Resolve", func(b *testing.B) { |
| 173 | for i := 0; i < b.N; i++ { |
| 174 | apis, mappings = resolveAPIs(ctx) |
| 175 | } |
| 176 | }) |
| 177 | |
| 178 | var data []byte |
| 179 | |
| 180 | // Time how long it takes to encode |
| 181 | b.Run("Encode", func(b *testing.B) { |
| 182 | for i := 0; i < b.N; i++ { |
| 183 | var err error |
| 184 | data, err = bapi.Encode(apis, mappings) |
| 185 | check(err) |
| 186 | } |
| 187 | }) |
| 188 | |
| 189 | // Time how long it takes to decode |
| 190 | b.Run("Decode", func(b *testing.B) { |
| 191 | for i := 0; i < b.N; i++ { |
| 192 | _, _, err := bapi.Decode(data) |
| 193 | check(err) |
| 194 | } |
| 195 | }) |
| 196 | |
| 197 | // Compress using different compressors and measure the decompression time |
| 198 | for _, f := range compressors { |
| 199 | b.Run(f.name, func(b *testing.B) { |
| 200 | c := f.compress(data) |
| 201 | b.Log("Compressed size: ", len(c)) |
| 202 | b.ResetTimer() |
| 203 | for i := 0; i < b.N; i++ { |
| 204 | f.decompress(c) |
| 205 | } |
| 206 | }) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | func resolveAPIs(ctx context.Context) ([]*semantic.API, *semantic.Mappings) { |
| 211 | apis := []*semantic.API{} |
nothing calls this directly
no test coverage detected