Tcl/Tk Benchmark Suite And Tools
Artifact Content
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2018 Conference, Houston/TX, US, Oct 15-19
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Aug 20.

Artifact 452964ddf8fb67a2fc9c286a8e3210056a551876:


# Unsetting an existing variable
proc unset-std {i} {
    set i 0
    unset i
}

# Catching invalid unset
proc unset-error {i} {
    set i 0
    catch {unset j}
}

# Catching valid unset
proc unset-ok {i} {
    set i 0
    catch {unset i}
}

# Testing existence befor unset
proc unset-exists {i} {
    set i 0
    if {[info exists i]} {
	unset i
    }
}

proc unset-nonexists {i} {
    set i 0
    if {[info exists j]} {
	unset j
    }
}

if {[catch {unset -nocomplain}]} {
    proc unset-nocomplain-exists {i} [info body unset-ok]
    proc unset-nocomplain-!exist {i} [info body unset-error]
} else {
    proc unset-nocomplain-exists {i} {
	set i 0
	unset -nocomplain i
    }
    proc unset-nocomplain-!exist {i} {
	set i 0
	unset -nocomplain j
    }
}

set iters 10000
bench -iter $iters -desc "UNSET var exists" \
	-body {unset-std a}
bench -iter $iters -desc "UNSET catch var exists" \
	-body {unset-ok a}
bench -iter $iters -desc "UNSET catch var !exist" \
	-body {unset-error a}
bench -iter $iters -desc "UNSET info check var exists" \
	-body {unset-exists a}
bench -iter $iters -desc "UNSET info check var !exist" \
	-body {unset-nonexists a}
bench -iter $iters -desc "UNSET nocomplain var exists" \
	-body {unset-nocomplain-exists a}
bench -iter $iters -desc "UNSET nocomplain var !exist" \
	-body {unset-nocomplain-!exist a}