summaryrefslogtreecommitdiffstats
path: root/tcllib/modules/asn/asn.bench
blob: cadac67863daf60970c83d2d89344af8aa28faa0 (plain)
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
# -*- tcl -*-
# Tcl Benchmark File
#
# This file contains a number of benchmarks for the 'asn' module.
# This allow developers to monitor/gauge/track package performance.
#
# (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net>

# We need at least version 8.2 for the package and thus the
# benchmarks.

if {![package vsatisfies [package provide Tcl] 8.4]} {
    return
}

# ### ### ### ######### ######### ######### ###########################
## Setting up the environment ...

package forget log
catch {namespace delete ::log}
source [file join [file dirname [file dirname [info script]]] log log.tcl]

package forget asn
catch {namespace delete ::asn}
source [file join [file dirname [info script]] asn.tcl]

# ### ### ### ######### ######### ######### ###########################
## Benchmarks.

foreach n {
    -10 -100 -1000 -10000 -100000 -1000000
    0
    10 100 1000 10000 100000 1000000
} {
    bench -desc "ASN Integer $n" -body {
	asn::asnInteger $n
    }

    bench -desc "ASN Enum $n" -body {
	asn::asnEnumeration $n
    }

    bench -desc "ASN Boolean $n" -body {
	asn::asnBoolean $n
    }
}

foreach n {10 100 1000 10000} {
    bench -desc "ASN OctetString ${n}" -pre {
	set str [string repeat X $n]
    } -body {
	asn::asnOctetString $str
    } -post {
	unset str
    }
}

for {set n 1; set i 0} {$i < 64} { set n [expr {wide($n)*2}] ; incr i} {
    bench -desc "ASN asnLength 2^${i}" -body {
	asn::asnLength $n
    }
}

for {set n 0} {$n < 10} { incr n} {
    bench -desc "ASN encode oid with ${n}+2 components" -pre {
	set oid [list 1 10]
	for {set i 0} {$i < $n} {incr i} {
	    lappend oid $i
	}
    } -body {
	asn::asnObjectIdentifier $oid
    } -post {
	unset oid
    }
}

for {set n 0} {$n < 10} { incr n} {
    bench -desc "ASN decode oid with ${n}+2 components" -pre {
	set oid [list 1 10]
	for {set i 0} {$i < $n} {incr i} {
	    lappend oid $i
	}
	set oidval [asn::asnObjectIdentifier $oid]
    } -body {
	asn::asnGetObjectIdentifier $oidval
    } -post {
	unset oid
	unset oidval
    }
}

foreach n {10 100 1000 10000 100000} {
    bench -desc "ASN asnGetByte ${n}" -pre {
	set bytes [binary format a* [string repeat X $n]]
    } -body {
	::asn::asnGetByte bytes dummy
    } -post {
	unset bytes
	unset dummy
    }
}


foreach n {10 100 1000 10000 100000} {
    bench -desc "ASN asnGetBytes ${n} len 5" -pre {
	set bytes [binary format a* [string repeat X $n]]
    } -body {
	::asn::asnGetBytes bytes 5 dummy
    } -post {
	unset bytes
	unset dummy
    }
}

# ### ### ### ######### ######### ######### ###########################
## Complete