MCPcopy
hub / github.com/go-sql-driver/mysql / BenchmarkQueryRawBytes

Function BenchmarkQueryRawBytes

benchmark_test.go:335–385  ·  view source on GitHub ↗

BenchmarkQueryRawBytes benchmarks fetching 100 blobs using sql.RawBytes. "size=" means size of each blobs.

(b *testing.B)

Source from the content-addressed store, hash-verified

333// BenchmarkQueryRawBytes benchmarks fetching 100 blobs using sql.RawBytes.
334// "size=" means size of each blobs.
335func BenchmarkQueryRawBytes(b *testing.B) {
336 var sizes []int = []int{100, 1000, 2000, 4000, 8000, 12000, 16000, 32000, 64000, 256000}
337 db := initDB(b, false,
338 "DROP TABLE IF EXISTS bench_rawbytes",
339 "CREATE TABLE bench_rawbytes (id INT PRIMARY KEY, val LONGBLOB)",
340 )
341 defer db.Close()
342
343 blob := make([]byte, sizes[len(sizes)-1])
344 for i := range blob {
345 blob[i] = 42
346 }
347 for i := range 100 {
348 _, err := db.Exec("INSERT INTO bench_rawbytes VALUES (?, ?)", i, blob)
349 if err != nil {
350 b.Fatal(err)
351 }
352 }
353
354 for _, s := range sizes {
355 b.Run(fmt.Sprintf("size=%v", s), func(b *testing.B) {
356 db.SetMaxIdleConns(0)
357 db.SetMaxIdleConns(1)
358 b.ReportAllocs()
359 b.ResetTimer()
360
361 for j := 0; j < b.N; j++ {
362 rows, err := db.Query("SELECT LEFT(val, ?) as v FROM bench_rawbytes", s)
363 if err != nil {
364 b.Fatal(err)
365 }
366 nrows := 0
367 for rows.Next() {
368 var buf sql.RawBytes
369 err := rows.Scan(&buf)
370 if err != nil {
371 b.Fatal(err)
372 }
373 if len(buf) != s {
374 b.Fatalf("size mismatch: expected %v, got %v", s, len(buf))
375 }
376 nrows++
377 }
378 rows.Close()
379 if nrows != 100 {
380 b.Fatalf("numbers of rows mismatch: expected %v, got %v", 100, nrows)
381 }
382 }
383 })
384 }
385}
386
387func benchmark10kRows(b *testing.B, compress bool) {
388 // Setup -- prepare 10000 rows.

Callers

nothing calls this directly

Calls 6

initDBFunction · 0.85
ScanMethod · 0.80
CloseMethod · 0.45
ExecMethod · 0.45
QueryMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected