#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2007 Tarek Ziadé
#
# Authors:
#   Tarek Ziadé <tarek@ziade.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
from test.pystone import pystones
import time

ratio = 0
timedtest_results = []

def clear():
    global timedtest_results
    timedtest_results = []

def reset():
    index = pystones()
    global ratio
    ratio = float(index[1]) / index[0]

def timedtest(function):
    """prints a pystone result"""
    def wrap(*args, **kw):
        start = time.time()
        try:
            return function(*args, **kw)
        finally:
            end = time.time() - start
            if end == 0:
                value = 0
            else:
                value = end * ratio
            timedtest_results.append(value)
    return wrap

def faster(delta=0):
    try:
        return timedtest_results[0] - timedtest_results[1] > delta
    finally:
        clear()

reset()

