# -*- tcl -*-
# Tcl Benchmark File
#
# This file contains a number of benchmarks for the 'yaml' module.
# This allow developers to monitor/gauge/track package performance.
#
# Copyright (c) 2008 by KATO Kanryu <kanryu6@users.sourceforge.net>

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

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

# ### ### ### ######### ######### ######### ###########################
## Setting up the environment ...
## Here we are testing version 2.

if {[lsearch [namespace children] ::bench] == -1} {
    # single test
    set selfrun 1
    lappend auto_path [pwd]
    package require bench
    puts [package require yaml]
} else {
    # all.tcl
    set moddir [file dirname [file dirname [info script]]]
    lappend auto_path $moddir

    source [file join [file dirname [info script]] yaml.tcl]
}

set Invoice {
--- # !<tag:clarkevans.com,2002:invoice>
invoice: 34843
date   : 2001-01-23
bill-to: &id001
    given  : Chris
    family : Dumars
    address:
        lines: |
            458 Walkman Dr.
            Suite #292
        city    : Royal Oak
        state   : MI
        postal  : 48046
ship-to: *id001
product:
    - sku         : BL394D
      quantity    : 4
      description : Basketball
      price       : 450.00
    - sku         : BL4438H
      quantity    : 1
      description : Super Hoop
      price       : 2392.00
tax  : 251.42
total: 4443.52
comments:
    Late afternoon is best.
    Backup contact is Nancy
    Billsmer @ 338-4338.
}

set huddle {HUDDLE {!!map {invoice {!!int 34843} date {!!timestamp 980175600} bill-to {!!map {given {!!str Chris} family {!!str Dumars} address {!!map {lines {!!str {458 Walkman Dr.
Suite #292
}} city {!!str {Royal Oak}} state {!!str MI} postal {!!int 48046}}}}} ship-to {!!map {given {!!str Chris} family {!!str Dumars} address {!!map {lines {!!str {458 Walkman Dr.
Suite #292
}} city {!!str {Royal Oak}} state {!!str MI} postal {!!int 48046}}}}} product {!!seq {{!!map {sku {!!str BL394D} quantity {!!int 4} description {!!str Basketball} price {!!float 450.00}}} {!!map {sku 
  {!!str BL4438H} quantity {!!int 1} description {!!str {Super Hoop}} price {!!float 2392.00}}}}} tax {!!float 251.42} total {!!float 4443.52} comments {!!str {Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.}}}}}

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

foreach n {1 10 100 1000} {
    bench -desc "yaml yaml2dict $n" -body {
        yaml::yaml2dict $Invoice
    }

    bench -desc "yaml huddle2yaml $n" -body {
        yaml::huddle2yaml $huddle
    }
}

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