Revision: 1078
Author: tim.bunce
Date: Sun Feb 21 08:22:38 2010
Log: Avoided repeat reads from DATA in t/42-global.t
Made t/61-cputime.t more chatty and moved code to __DATA__
http://code.google.com/p/perl-devel-nytprof/source/detail?r=1078
Modified:
/trunk/t/42-global.t
/trunk/t/61-cputime.t
=======================================
--- /trunk/t/42-global.t Mon Jan 4 12:45:47 2010
+++ /trunk/t/42-global.t Sun Feb 21 08:22:38 2010
@@ -11,20 +11,14 @@
my $pre589 = ($] < 5.008009 or $] eq "5.010000");
+my $src_code = join("", <DATA>);
+
run_test_group( {
extra_options => { start => 'begin' },
extra_test_count => 16,
extra_test_code => sub {
my ($profile, $env) = @_;
- my $src_code = q{
- sub foo { 42 }
- BEGIN {
- foo(2);
- *CORE::GLOBAL::sleep = \&foo;
- }
- sleep 1;
- };
$profile = profile_this(
src_code => $src_code,
out_file => $env->{file},
@@ -66,3 +60,12 @@
},
});
+
+__DATA__
+#!perl
+sub foo { 42 }
+BEGIN {
+ foo(2);
+ *CORE::GLOBAL::sleep = \&foo;
+}
+sleep 1;
=======================================
--- /trunk/t/61-cputime.t Sat Feb 20 05:21:47 2010
+++ /trunk/t/61-cputime.t Sun Feb 21 08:22:38 2010
@@ -9,6 +9,8 @@
use Devel::NYTProf::Run qw(profile_this);
+my $src_code = join("", <DATA>);
+
run_test_group( {
extra_options => {
# set options for this test:
@@ -20,42 +22,6 @@
extra_test_code => sub {
my ($profile, $env) = @_;
- my $src_code = q{
- alarm(20); # watchdog timer
- my $cpu1 = (times)[0];
- my $cpu2;
-
- sub 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;
- }
- print "cputime loop count $loops\n";
- }
-
- # sync up: spin till clock ticks
- 1 while $cpu1 == ($cpu2 = (times)[0]);
- print "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
- print "realtime used ".(time()-$start)."\n";
-
- };
$profile = profile_this(
src_code => $src_code,
out_file => $env->{file},
@@ -72,3 +38,46 @@
is $sub->incl_time, $sub->excl_time, 'incl_time and excl_time
should be the same';
},
});
+
+__DATA__
+#!perl
+
+alarm(20); # watchdog timer
+
+my $trace = 0;
+my $cpu1 = (times)[0];
+my $cpu2;
+
+sub foo {
+ my $end = shift;
+
+ # sleep to separate cputime from realtime
+ # (not very effective in cpu-starved VMs)
+ sleep 1;
+
+ my $loops = 0;
+ my $prev;
+ while (++$loops) {
+
+ my $crnt = (times)[0];
+ warn "tick $crnt ".time()."\n"
+ if $crnt != $prev and $trace >= 2;
+ $prev = $crnt;
+
+ last if $crnt >= $end;
+ }
+ warn "cputime loop count $loops\n" if $trace;
+}
+
+# sync up: spin till clock ticks
+1 while $cpu1 == ($cpu2 = (times)[0]);
+warn "cputime step ".($cpu2-$cpu1)."\n" if $trace;
+
+# 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
+print "realtime used ".(time()-$start)."\n" if $trace;
--
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]