in reply to Getting timing details from a test

As far as I can tell, all calls to the standard testing functions eventually go through sub ok in cpan/Test-Simple/lib/Test/Builder.pm in perl.git. If you override this sub, you could get a timestamp per individual sub test.

If you just want one number, you could modify the test harness to do the timing on the caller side. Or you could write your own harness with TAP::Harness -- don't worry, it's not much work at all, TAP::Harness does all the hard parts for you.

Replies are listed 'Best First'.
Re^2: Getting timing details from a test
by mcdave (Beadle) on May 29, 2012 at 16:49 UTC
    I'm revisiting this year-old question because I had occasion last week to try to do this benchmark-plus-test thing in an extensible way and came up against some funny roadblocks. The most amusing/irritating was that overriding sub ok turned out to be a total bust! So I'll comment for posterity (which will include my future self) about why.

    Quite simply, ok just reads the result of the test. So in ok(&test1, 'the first test') ; the ok method doesn't get invoked at all until test1 has finished. Hence, all my tests were showing up as instantaneous (because I was really just measuring time it took to call the ok method itself). What I need, somehow, is a version of "ok" that takes a subroutine as its first argument rather than a string then times the execution.

    As part of the process, though, I came across Test::More::Diagnostic which seems like the right kind of idea for augmenting my outputs so that future executions can be compared to baseline. This seems like a version of "write your own harness," and I'm hoping it won't be all that difficult.