Revision: 1066
Author: tim.bunce
Date: Sat Feb 20 03:56:13 2010
Log: Updated cputime time test to better identify when cputime is really measuring realtime
(which it is on OS X at the moment)

http://code.google.com/p/perl-devel-nytprof/source/detail?r=1066

Modified:
 /trunk/t/61-cputime.t

=======================================
--- /trunk/t/61-cputime.t       Sat Feb 20 03:29:53 2010
+++ /trunk/t/61-cputime.t       Sat Feb 20 03:56:13 2010
@@ -22,16 +22,39 @@

         my $src_code = q{
             alarm(20); # watchdog timer
+            my $cpu1 = (times)[0];
+            my $cpu2;
+
             sub foo {
-                my $wait = 0.5; # consume this much cpu time inside foo()
-                my $cpu1 = (times)[0];
-                while (1) {
-                    my $cpu2 = (times)[0];
-                    last if $cpu2 > $cpu1 + $wait;
-                }
-            }
- # could spin waiting for (times)[0] to change before calling foo
-            foo();
+                my $end = shift;
+                sleep 1; # to separate cputime from realtime
+
+                my $loops = 0;
+                my $prev;
+                while (++$loops) {
+
+                    my $crnt = (times)[0];
+                    #print "tick $crnt\n" if $crnt != $prev;
+                    $prev = $crnt;
+
+                    last if $crnt >= $end;
+                }
+                warn "cputime loop count $loops\n";
+            }
+
+            # sync up: spin till clock ticks
+            1 while $cpu1 == ($cpu2 = (times)[0]);
+            warn "cputime step ".($cpu2-$cpu1)."\n";
+
+            # record start time
+            my $start = time();
+
+            # consume this much cpu time inside foo()
+            foo($cpu2 + 0.4);
+
+ # report realtime to help identify is cputime is really measuring realtime
+            warn "realtime used ".(time()-$start)."\n";
+
         };
         $profile = profile_this(
             src_code => $src_code,
@@ -46,5 +69,6 @@
         is $sub->calls, 1, 'main::foo should be called 1 times';
cmp_ok $sub->incl_time, '>', 0.4, 'cputime of foo() should be at least ~0.5'; cmp_ok $sub->incl_time, '<', 1.0, 'cputime of foo() should be around 0.5'; + is $sub->incl_time, $sub->excl_time, 'incl_time and excl_time should be the same';
     },
 });

--
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]

Reply via email to