]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the test/speedtest.tcl script to simplify performance and size testing.
authordrh <>
Fri, 17 Jan 2025 12:32:01 +0000 (12:32 +0000)
committerdrh <>
Fri, 17 Jan 2025 12:32:01 +0000 (12:32 +0000)
FossilOrigin-Name: ad7b38672656d0336a73bb789ec83f6939fbdae81e21be68e0313006826dc294

manifest
manifest.uuid
test/speedtest.tcl [new file with mode: 0755]

index 4ddace420aeca9fa57a7a49b903e7d288125831b..33319f9174fe28a1c42ac3439896e2262ac96427 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\spotential\sone-byte\sbuffer\soverrun\swhen\sreading\sfrom\sthe\sWindows\nconsole\sin\sthe\sCLI.\s[forum:/forumpost/95e17b8f5c|Forum\spost\s95e17b8f5c].
-D 2025-01-17T10:39:04.650
+C Add\sthe\stest/speedtest.tcl\sscript\sto\ssimplify\sperformance\sand\ssize\stesting.
+D 2025-01-17T12:32:01.367
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@@ -1677,6 +1677,7 @@ F test/speed3.test 694affeb9100526007436334cf7d08f3d74b85ef
 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715
 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa
 F test/speed4p.test 377a0c48e5a92e0b11c1c5ebb1bc9d83a7312c922bc0cb05970ef5d6a96d1f0c
+F test/speedtest.tcl 76a0959d7d16cbebae49756bbb858a3d2f1d9081e757c87cb7fea7c816d1c575 x
 F test/speedtest1.c 323ce0956430a5aae56ea20f502da7bea3fb62b8ed02e9b0f12ab078b2b258f5
 F test/spellfix.test 951a6405d49d1a23d6b78027d3877b4a33eeb8221dcab5704b499755bb4f552e
 F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3
@@ -2205,8 +2206,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P c4750f7cf7e2188623de8b12e01acf3e3d7dc7b5ea87ac449571eb36f97d842a
-R 45a83a05156d426ada8c2c9a4e3fc01c
+P 4d96759694c91301410f53a3f737a049c33e8b259b0954ff659714aff8b21ae8
+R 7f163047a093ae4e315e910ea1611ab4
 U drh
-Z 4047e2705a87b112269cd6828f65ee7b
+Z 4d5c65aabce50a5f7c599ac5c2690d5d
 # Remove this line to create a well-formed Fossil manifest.
index ce8658f845f8bd9c00bd89bfb205cb190b315c73..36403859dc57c060a2f69a1b6060504a0b8d8df6 100644 (file)
@@ -1 +1 @@
-4d96759694c91301410f53a3f737a049c33e8b259b0954ff659714aff8b21ae8
+ad7b38672656d0336a73bb789ec83f6939fbdae81e21be68e0313006826dc294
diff --git a/test/speedtest.tcl b/test/speedtest.tcl
new file mode 100755 (executable)
index 0000000..1d6cf4e
--- /dev/null
@@ -0,0 +1,271 @@
+#!/bin/sh
+# the next line restarts using tclsh \
+exec tclsh "$0" ${1+"$@"}
+#
+# This program runs performance testing on sqlite3.c.  Usage:
+set usage {USAGE:
+
+  speedtest.tcl  sqlite3.c  x1.txt  trunk.txt  -Os -DSQLITE_ENABLE_STAT4
+                     |         |        |       `-----------------------'
+    File to test ----'         |        |                |
+                               |        |                `- options
+       Output filename --------'        |
+                                        `--- optional prior output to diff
+
+Do a cache-grind performance analysis of the sqlite3.c file named and
+write the results into the output file.  The ".txt" is appended to the
+output file (and diff-file) name if it is not already present.  If the
+diff-file is specified then show a diff from the diff-file to the new
+output.
+
+Other options include:
+   --dryrun              Show what would happen but don't do anything
+   --help                Show this help screen
+   --lean                "Lean" mode.
+   --lookaside N SZ      Lookahead uses N slots of SZ bytes each
+   --pagesize N          Use N as the page size
+}
+set srcfile {}
+set outfile {}
+set difffile {}
+set cflags {}
+set cc gcc
+set testset mix1
+set dryrun 0
+set speedtestflags {--shrink-memory --reprepare --stats --heap 40000000 64}
+lappend speedtestflags --journal wal --size 5
+
+for {set i 0} {$i<[llength $argv]} {incr i} {
+  set arg [lindex $argv $i]
+  if {[string index $arg 0]=="-"} {
+    switch -- $arg {
+      -pagesize -
+      --pagesize {
+        lappend speedtestflags --pagesize
+        incr i
+        lappend speedtestflags [lindex $argv $i]
+      }
+      -lookaside -
+      --lookaside {
+        lappend speedtestflags --lookaside
+        incr i
+        lappend speedtestflags [lindex $argv $i]
+        incr i
+        lappend speedtestflags [lindex $argv $i]
+      }
+      -lean -
+      --lean {
+        lappend cflags \
+           -DSQLITE_DEFAULT_MEMSTATUS=0 \
+           -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 \
+           -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 \
+           -DSQLITE_MAX_EXPR_DEPTH=1 \
+           -DSQLITE_OMIT_DECLTYPE \
+           -DSQLITE_OMIT_DEPRECATED \
+           -DSQLITE_OMIT_PROGRESS_CALLBACK \
+           -DSQLITE_OMIT_SHARED_CACHE \
+           -DSQLITE_USE_ALLOCA
+      }
+      -n -
+      -dryrun -
+      --dryrun {
+        set dryrun 1
+      }
+      -? -
+      -help -
+      --help {
+        puts $usage
+        exit 0
+      }
+      default {
+        lappend cflags $arg
+      }
+    }
+    continue
+  }
+  if {[string match CC=* $arg]} {
+    set cc [lrange $arg 3 end]
+    continue
+  }
+  if {[string match *.c $arg]} {
+    if {$srcfile!=""} {
+      puts stderr "multiple source files: $srcfile $arg"
+      exit 1
+    }
+    set srcfile $arg
+    continue
+  }
+  if {[lsearch {main cte rtree orm fp json parsenumber mix1} $arg]>=0} {
+    set testset $arg
+    continue
+  }
+  if {$outfile==""} {
+    set outfile $arg
+    continue
+  }
+  if {$difffile==""} {
+    set difffile $arg
+    continue
+  }
+  puts stderr "unknown option: \"$arg\".  Use --help for more info."
+  exit 1
+}
+if {[lsearch -glob $cflags -O*]<0} {
+  lappend cflags -Os
+}
+if {[lsearch -glob $cflags -DSQLITE_ENABLE_MEMSYS*]<0} {
+  lappend cflags -DSQLITE_ENABLE_MEMSYS5
+}
+if {[lsearch -glob $cflags -DSQLITE_ENABLE_RTREE*]<0} {
+  lappend cflags -DSQLITE_ENABLE_RTREE
+}
+if {$srcfile==""} {
+  puts stderr "no sqlite3.c source file specified"
+  exit 1
+}
+if {![file readable $srcfile]} {
+  puts stderr "source file \"$srcfile\" does not exist"
+  exit 1
+}
+if {$outfile==""} {
+  puts stderr "no output file specified"
+  exit 1
+}
+if {![string match *.* [file tail $outfile]]} {
+  append outfile .txt
+}
+if {$difffile!=""} {
+  if {![file exists $difffile]} {
+    if {[file exists $difffile.txt]} {
+      append difffile .txt
+    } else {
+      puts stderr "No such file: \"$difffile\""
+      exit 1
+    }
+  }
+}
+
+set cccmd [list $cc -g]
+lappend cccmd -I[file dir $srcfile]
+lappend cccmd {*}[lsort $cflags]
+lappend cccmd [file dir $argv0]/speedtest1.c
+lappend cccmd $srcfile
+lappend cccmd -o speedtest1
+puts $cccmd
+if {!$dryrun} {
+  exec {*}$cccmd
+}
+lappend speedtestflags --testset $testset
+set stcmd [list valgrind --tool=cachegrind ./speedtest1 {*}$speedtestflags]
+lappend stcmd >valgrind-out.txt 2>valgrind-err.txt
+puts $stcmd
+if {!$dryrun} {
+   exec {*}$stcmd
+}
+
+set maxmtime 0
+set cgfile {}
+foreach cgout [glob -nocomplain cachegrind.out.*] {
+  if {[file mtime $cgout]>$maxmtime} {
+    set cgfile $cgout
+    set maxmtime [file mtime $cgfile]
+  }
+}
+if {$cgfile==""} {
+  puts "no cachegrind output"
+  exit 1
+}
+
+############# Process the cachegrind.out.# file ##########################
+set fd [open $outfile wb]
+set in [open "|cg_annotate --show=Ir --auto=yes --context=40 $cgfile" r]
+set dest !
+set out(!) {}
+set linenum 0
+set cntlines 0      ;# true to remember cycle counts on each line
+set seenSqlite3 0   ;# true if we have seen the sqlite3.c file
+while {![eof $in]} {
+  set line [string map {\t {        }} [gets $in]]
+  if {[regexp {^-- Auto-annotated source: (.*)} $line all name]} {
+    set dest $name
+    if {[string match */sqlite3.c $dest]} {
+      set cntlines 1
+      set seenSqlite3 1
+    } else {
+      set cntlines 0
+    }
+  } elseif {[regexp {^-- line (\d+) ------} $line all ln]} {
+    set line [lreplace $line 2 2 {#}]
+    set linenum [expr {$ln-1}]
+  } elseif {[regexp {^The following files chosen for } $line]} {
+    set dest !
+  }
+  append out($dest) $line\n
+  if {$cntlines} {
+    incr linenum
+    if {[regexp {^ *([0-9,]+) } $line all x]} {
+      set x [string map {, {}} $x]
+      set cycles($linenum) $x
+    }
+  }
+}
+foreach x [lsort [array names out]] {
+  puts $fd $out($x)
+}
+# If the sqlite3.c file has been seen, then output a summary of the
+# cycle counts for each file that went into making up sqlite3.c
+#
+if {$seenSqlite3} {
+  close $in
+  set in [open sqlite3.c]
+  set linenum 0
+  set fn sqlite3.c
+  set pattern1 {^/\*+ Begin file ([^ ]+) \*}
+  set pattern2 {^/\*+ Continuing where we left off in ([^ ]+) \*}
+  while {![eof $in]} {
+    set line [gets $in]
+    incr linenum
+    if {[regexp $pattern1 $line all newfn]} {
+      set fn $newfn
+    } elseif {[regexp $pattern2 $line all newfn]} {
+      set fn $newfn
+    } elseif {[info exists cycles($linenum)]} {
+      incr fcycles($fn) $cycles($linenum)
+    }
+  }
+  close $in
+  puts $fd \
+     {**********************************************************************}
+  set lx {}
+  set sum 0
+  foreach {fn cnt} [array get fcycles] {
+    lappend lx [list $cnt $fn]
+    incr sum $cnt
+  }
+  puts $fd [format {%20s %14d  %8.3f%%} TOTAL $sum 100]
+  foreach entry [lsort -index 0 -integer -decreasing $lx] {
+    foreach {cnt fn} $entry break
+    puts $fd [format {%20s %14d  %8.3f%%} $fn $cnt [expr {$cnt*100.0/$sum}]]
+  }
+}
+puts $fd "Executable size:"
+close $fd
+exec size speedtest1 >>$outfile
+#
+#  Processed cachegrind output should now be in the $outfile
+#############################################################################
+
+if {$difffile!=""} {
+  set fossilcmd {fossil xdiff --tk -c 20}
+  lappend fossilcmd $difffile
+  lappend fossilcmd $outfile
+  lappend fossilcmd &
+  puts $fossilcmd
+  if {!$dryrun} {
+    exec {*}$fossilcmd
+  }
+} else {
+  if {!$dryrun} {
+    exec open $outfile
+  }
+}