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

Function BenchmarkReceiveMetadata

benchmark_test.go:459–511  ·  view source on GitHub ↗

BenchmarkReceiveMetadata measures performance of receiving lots of metadata compare to data in rows

(b *testing.B)

Source from the content-addressed store, hash-verified

457
458// BenchmarkReceiveMetadata measures performance of receiving lots of metadata compare to data in rows
459func BenchmarkReceiveMetadata(b *testing.B) {
460 tb := (*TB)(b)
461
462 // Create a table with 1000 integer fields
463 var createTableQuery strings.Builder
464 createTableQuery.WriteString("CREATE TABLE large_integer_table (")
465 for i := range 1000 {
466 createTableQuery.WriteString(fmt.Sprintf("col_%d INT", i))
467 if i < 999 {
468 createTableQuery.WriteString(", ")
469 }
470 }
471 createTableQuery.WriteString(")")
472
473 // Initialize database
474 db := initDB(b, false,
475 "DROP TABLE IF EXISTS large_integer_table",
476 createTableQuery.String(),
477 "INSERT INTO large_integer_table VALUES ("+
478 strings.Repeat("0,", 999)+"0)", // Insert a row of zeros
479 )
480 defer db.Close()
481
482 b.Run("query", func(b *testing.B) {
483 db.SetMaxIdleConns(0)
484 db.SetMaxIdleConns(1)
485
486 // Create a slice to scan all columns
487 values := make([]any, 1000)
488 valuePtrs := make([]any, 1000)
489 for j := range values {
490 valuePtrs[j] = &values[j]
491 }
492
493 // Prepare a SELECT query to retrieve metadata
494 stmt := tb.checkStmt(db.Prepare("SELECT * FROM large_integer_table LIMIT 1"))
495 defer stmt.Close()
496
497 // Benchmark metadata retrieval
498 b.ReportAllocs()
499 b.ResetTimer()
500 for range b.N {
501 rows := tb.checkRows(stmt.Query())
502
503 rows.Next()
504 // Scan the row
505 err := rows.Scan(valuePtrs...)
506 tb.check(err)
507
508 rows.Close()
509 }
510 })
511}

Callers

nothing calls this directly

Calls 10

initDBFunction · 0.85
StringMethod · 0.80
checkStmtMethod · 0.80
PrepareMethod · 0.80
checkRowsMethod · 0.80
ScanMethod · 0.80
checkMethod · 0.80
CloseMethod · 0.45
QueryMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected