summaryrefslogtreecommitdiffstats
path: root/tcllib/modules/json/json.bench
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 19:39:39 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 19:39:39 (GMT)
commitea28451286d3ea4a772fa174483f9a7a66bb1ab3 (patch)
tree6ee9d8a7848333a7ceeee3b13d492e40225f8b86 /tcllib/modules/json/json.bench
parentb5ca09bae0d6a1edce939eea03594dd56383f2c8 (diff)
parent7c621da28f07e449ad90c387344f07a453927569 (diff)
downloadblt-ea28451286d3ea4a772fa174483f9a7a66bb1ab3.zip
blt-ea28451286d3ea4a772fa174483f9a7a66bb1ab3.tar.gz
blt-ea28451286d3ea4a772fa174483f9a7a66bb1ab3.tar.bz2
Merge commit '7c621da28f07e449ad90c387344f07a453927569' as 'tcllib'
Diffstat (limited to 'tcllib/modules/json/json.bench')
-rw-r--r--tcllib/modules/json/json.bench167
1 files changed, 167 insertions, 0 deletions
diff --git a/tcllib/modules/json/json.bench b/tcllib/modules/json/json.bench
new file mode 100644
index 0000000..fb08f29
--- /dev/null
+++ b/tcllib/modules/json/json.bench
@@ -0,0 +1,167 @@
+# -*- tcl -*-
+# Tcl Benchmark File
+#
+# This file contains a number of benchmarks for the 'json' parser
+# to allow developers to monitor package performance.
+#
+# (c) 2013 Andreas Kupries <andreas_kupries@users.sourceforge.net>
+
+# We need at least version 8.4 for the package and thus the
+# benchmarks.
+
+if {![package vsatisfies [package present Tcl] 8.4]} {
+ bench_puts "Need Tcl 8.4+, found Tcl [package present Tcl]"
+ return
+}
+
+# ### ### ### ######### ######### ######### ###########################
+## Setting up the environment ...
+
+package require Tcl 8.4
+
+package forget json
+
+set self [file join [pwd] [file dirname [info script]]]
+set mod [file dirname $self]
+set index [file join [file dirname $self] tcllibc pkgIndex.tcl]
+
+if 1 {
+ if {[file exists $index]} {
+ set ::dir [file dirname $index]
+ uplevel #0 [list source $index]
+ unset ::dir
+ package require tcllibc
+ }
+}
+
+source [file join $self json.tcl]
+
+# ### ### ### ######### ######### ######### ###########################
+## Helpers
+
+proc cat {f} {
+ set c [open $f]
+ set d [read $c]
+ close $c
+ return $d
+}
+
+proc iota {n} {
+ set r {}
+ while {$n > 0} {
+ lappend r [json::string2json $n]
+ incr n -1
+ }
+ return $r
+}
+
+proc iota-dict {n} {
+ set r {}
+ while {$n > 0} {
+ lappend r f$n [json::string2json $n]
+ incr n -1
+ }
+ return $r
+}
+
+# ### ### ### ######### ######### ######### ###########################
+## Get all the possible implementations
+
+json::SwitchTo {}
+foreach e [json::KnownImplementations] {
+ ::json::LoadAccelerator $e
+}
+
+# ### ### ### ######### ######### ######### ###########################
+## Benchmarks.
+## Just the parser, on the valid inputs for the testsuite.
+
+foreach impl [json::Implementations] {
+ json::SwitchTo $impl
+
+ if {$impl eq "tcl"} {
+ set series {0 1 10 100 1000}
+ } else {
+ set series {0 1 10 100 1000}
+ }
+
+ bench_puts "=== === === === === ==="
+ bench_puts "=== === === $impl ==="
+ bench_puts "=== === === === === ==="
+
+ bench_puts {=== test-data =========}
+
+ foreach f [glob -nocomplain -directory $self/tests *.json] {
+ set in [cat $f]
+
+ bench -desc "parse [file rootname [file tail $f]] ($impl)" -body {
+ json::json2dict $in
+ }
+
+ bench -desc "validate [file rootname [file tail $f]] ($impl)" -body {
+ json::validate $in
+ }
+ }
+
+ foreach f [glob -nocomplain -directory $self/tests *.bench] {
+ set in [cat $f]
+
+ bench -desc "parse [file rootname [file tail $f]] ($impl)" -body {
+ json::json2dict $in
+ }
+
+ bench -desc "validate [file rootname [file tail $f]] ($impl)" -body {
+ json::validate $in
+ }
+ }
+
+ bench_puts {=== synthetic array =========}
+
+ foreach n $series {
+ set in [json::list2json [iota $n]]
+
+ bench -desc "parse array-$n ($impl)" -body {
+ json::json2dict $in
+ }
+
+ bench -desc "validate array-$n ($impl)" -body {
+ json::validate $in
+ }
+ }
+
+ bench_puts {=== synthetic object =========}
+
+ foreach n $series {
+ set in [json::dict2json [iota-dict $n]]
+
+ bench -desc "parse object-$n ($impl)" -body {
+ json::json2dict $in
+ }
+
+ bench -desc "validate object-$n ($impl)" -body {
+ json::validate $in
+ }
+ }
+
+ bench_puts {=== synthetic string =========}
+
+ foreach n $series {
+ set in [json::string2json [string repeat . $n]]
+
+ bench -desc "parse string-$n ($impl)" -body {
+ json::json2dict $in
+ }
+
+ bench -desc "validate string-$n ($impl)" -body {
+ json::validate $in
+ }
+ }
+}
+
+# ### ### ### ######### ######### ######### ###########################
+## Complete
+
+return
+
+# ### ### ### ######### ######### ######### ###########################
+## Notes ...