MCPcopy Create free account
hub / github.com/DataDog/datadog-agent / BenchmarkObfuscateSQLString

Function BenchmarkObfuscateSQLString

pkg/obfuscate/sql_test.go:1845–1879  ·  view source on GitHub ↗

Benchmark the Tokenizer using a SQL statement

(b *testing.B)

Source from the content-addressed store, hash-verified

1843
1844// Benchmark the Tokenizer using a SQL statement
1845func BenchmarkObfuscateSQLString(b *testing.B) {
1846 benchmarks := []struct {
1847 name string
1848 query string
1849 }{
1850 {"Escaping", `INSERT INTO delayed_jobs (attempts, created_at, failed_at, handler, last_error, locked_at, locked_by, priority, queue, run_at, updated_at) VALUES (0, '2016-12-04 17:09:59', NULL, '--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/object:Item\n store:\n - a simple string\n - an \'escaped \' string\n - another \'escaped\' string\n - 42\n string: a string with many \\\\\'escapes\\\\\'\nmethod_name: :show_store\nargs: []\n', NULL, NULL, NULL, 0, NULL, '2016-12-04 17:09:59', '2016-12-04 17:09:59')`},
1851 {"Grouping", `INSERT INTO delayed_jobs (created_at, failed_at, handler) VALUES (0, '2016-12-04 17:09:59', NULL), (0, '2016-12-04 17:09:59', NULL), (0, '2016-12-04 17:09:59', NULL), (0, '2016-12-04 17:09:59', NULL)`},
1852 {"Large", LargeQuery},
1853 {"Complex", ComplexQuery},
1854 }
1855 obf := NewObfuscator(Config{})
1856 for _, bm := range benchmarks {
1857 b.Run(bm.name+"/"+strconv.Itoa(len(bm.query)), func(b *testing.B) {
1858 b.ResetTimer()
1859 b.ReportAllocs()
1860 for i := 0; i < b.N; i++ {
1861 _, err := obf.ObfuscateSQLStringWithOptions(bm.query, &SQLConfig{ReplaceDigits: true})
1862 if err != nil {
1863 b.Fatal(err)
1864 }
1865 }
1866 })
1867 }
1868
1869 b.Run("random", func(b *testing.B) {
1870 b.ReportAllocs()
1871 var j atomic.Uint64
1872 for i := 0; i < b.N; i++ {
1873 _, err := obf.ObfuscateSQLString(fmt.Sprintf("SELECT * FROM users WHERE id=%d", j.Inc()))
1874 if err != nil {
1875 b.Fatal(err)
1876 }
1877 }
1878 })
1879}
1880
1881// BenchmarkQueryCacheTippingPoint is meant to help evaluate the minimum cache hit rate needed for the
1882// query cache to become performance beneficial.

Callers

nothing calls this directly

Calls 5

ObfuscateSQLStringMethod · 0.95
NewObfuscatorFunction · 0.85
RunMethod · 0.65
IncMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…