# -*- tcl -*-
# loggerperformance.tcl
#
# This code is for benchmarking the performance of the log tools.

set auto_path "[file dirname [info script]] $auto_path"
package require logger
package require log

# Set up logger
set log [logger::init date]

# Create a custom log routine, so we don't deal with the overhead of
# the default one, which does some system calls itself.

${log}::logproc notice txt {
    puts "$txt"
}

# Basic output.
proc Test1 {} {
    set date [clock format [clock seconds]]
    puts "Date is now $date"
}

# No output at all.  This is the benchmark by which 'turned off' log
# systems should be judged.
proc Test2 {} {
    set date [clock format [clock seconds]]
}

# Use logger.
proc Test3 {} {
    set date [clock format [clock seconds]]
    ${::log}::notice "Date is now $date"
}

# Use log.
proc Test4 {} {
    set date [clock format [clock seconds]]
    log::log notice "Date is now $date"
}

set res1 [time {
    Test1
} 1000]

set res2 [time {
    Test2
} 1000]

set res3 [time {
    Test3
} 1000]

${log}::disable notice

set res4 [time {
    Test3
} 1000]

set res5 [time {
    Test4
} 1000]

log::lvSuppressLE notice

set res6 [time {
    Test4
} 1000]

puts "Puts output:		$res1"
puts "No output:		$res2"
puts "Logger:			$res3"
puts "Logger disabled: 	$res4"
puts "Log: 			$res5"
puts "Log disabled: 		$res6"
