public function profile($classname, $methodname, $methodargs, $invocations = 1)
    {
        if (class_exists($classname) != TRUE) {
            throw new Exception("{$classname} doesn't exist");
        }

        $method = new ReflectionMethod($classname, $methodname);

        $instance = NULL;
        if (!$method->isStatic()) {
            $class = new ReflectionClass($classname);
            $instance = $class->newInstance();
        }

        $durations = array();
        for ($i = 0; $i < $invocations; $i++) {
            $start = microtime(true);
            $method->invokeArgs($instance, $methodargs);
            $durations[] = microtime(true) - $start;
        }
        $durations['worst'] = round(max($durations), 5);
        $durations['total'] = round(array_sum($durations), 5);
        $durations['average'] = round($durations['total'] / count($durations), 5);


        $this->details = array('class' => $classname,
            'method' => $methodname,
            'arguments' => $methodargs,
            'duration' => $durations,
            'invocations' => $invocations);

        return $durations['average'];
    }