1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 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 ...
|