Author: gisle.aas
Date: Thu Oct 23 08:24:20 2008
New Revision: 547
Modified:
trunk/lib/Devel/NYTProf/Util.pm
trunk/t/30.util.t
Log:
Make fmt_incl_excl_time not repeat the unit
Modified: trunk/lib/Devel/NYTProf/Util.pm
==============================================================================
--- trunk/lib/Devel/NYTProf/Util.pm (original)
+++ trunk/lib/Devel/NYTProf/Util.pm Thu Oct 23 08:24:20 2008
@@ -161,7 +161,18 @@
my ($incl, $excl) = @_;
my $diff = $incl - $excl;
return fmt_time($incl) unless $diff;
- return sprintf "%s (%s+%s)", fmt_time($incl), fmt_time($excl),
fmt_time($diff);
+ $_ = fmt_time($_) for $incl, $excl, $diff;
+ if ($incl =~ /(\D+)$/) {
+ # no need to repeat the unit if it's the same for all time stamps
+ my $unit = $1;
+ my $offset = -length($unit);
+ for ($excl, $diff) {
+ if (/(\D+)$/) {
+ substr($_, $offset) = "" if $1 eq $unit
+ }
+ }
+ }
+ return sprintf "%s (%s+%s)", $incl, $excl, $diff;
}
Modified: trunk/t/30.util.t
==============================================================================
--- trunk/t/30.util.t (original)
+++ trunk/t/30.util.t Thu Oct 23 08:24:20 2008
@@ -1,6 +1,6 @@
-use Test::More tests => 15;
+use Test::More tests => 20;
-use Devel::NYTProf::Util qw(fmt_time);
+use Devel::NYTProf::Util qw(fmt_time fmt_incl_excl_time);
my $us = "µs";
@@ -20,3 +20,10 @@
is(fmt_time(1.1253e+1), "11.3s");
is(fmt_time(1.1253e+2), "113s");
is(fmt_time(1.1253e+3), "1125s");
+
+is(fmt_incl_excl_time(3, 3), "3.00s");
+is(fmt_incl_excl_time(3, 2), "3.00s (2.00+1.00)");
+is(fmt_incl_excl_time(3, 2.997), "3.00s (3.00+3.00ms)");
+is(fmt_incl_excl_time(0.1, 0.0997), "100ms (99.7+300$us)");
+is(fmt_incl_excl_time(1.1e-5, 3.5e-6), "11$us (4+8)");
+
--~--~---------~--~----~------------~-------~--~----~
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.
Group hosted at: http://groups.google.com/group/develnytprof-dev
Project hosted at: http://perl-devel-nytprof.googlecode.com
CPAN distribution: http://search.cpan.org/dist/Devel-NYTProf
To post, email: [email protected]
To unsubscribe, email: [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---