Author: tim.bunce
Date: Mon Dec  1 01:55:49 2008
New Revision: 635

Modified:
    trunk/demo/demo-code.pl
    trunk/demo/demo-run.pl

Log:
Reorg the demo code. Run the while(<>) example and update
the comments to reflect the fact it should work (but currently doesn't)


Modified: trunk/demo/demo-code.pl
==============================================================================
--- trunk/demo/demo-code.pl     (original)
+++ trunk/demo/demo-code.pl     Mon Dec  1 01:55:49 2008
@@ -5,23 +5,13 @@
  my $count = shift || 100;
  my $do_io = shift || 0;

-
  sub add {
      $a = $a + 1;
      foo();
  }

-sub inc {
-    ++$a;
-    # call foo and then execute a slow expression *in the same statement*
-    # With all line profilers except NYTProf, the time for that expression  
gets
-    # assigned to the previous statement, i.e., the last statement  
executed in foo()!
-    foo() && 'aaaaaaaaaaa' =~ /((a{0,5}){0,5})*[c]/;
-}
-
  sub foo {
      1;
-    1;
      for (1..1000) {
          ++$a;
          ++$a;
@@ -29,9 +19,13 @@
      1;
  }

-END {
-    warn "END!\n";
-    add()
+sub inc {
+    1;
+    # call foo and then execute a slow expression *in the same statement*
+    # With all line profilers except NYTProf, the time for that expression  
gets
+    # assigned to the previous statement, i.e., the last statement  
executed in foo()!
+    foo() && 'aaaaaaaaaaa' =~ /((a{0,5}){0,5})*[c]/;
+    1;
  }

  timethese( $count, {
@@ -39,6 +33,11 @@
      bar => \&inc,
  });

+END {
+    warn "ENDING\n";
+    add()
+}
+

  # --- recursion ---

@@ -49,25 +48,25 @@
  }
  fib(7);

+# --- File::Find ---
+
+sub wanted {
+    return 1;
+}
+
+find( \&wanted, '.');
+

  # --- while with slow conditional ---

  if ($do_io) {
-    print "Enter text. Enter empty line to end.\n";
-    # With all line profilers before NYTProf, the time waiting for the
-    # second and subsequent inputs gets assigned to the previous statement,
-    # i.e., the last statement executed in the loop!
+    print "Enter text. Enter empty line to end.\n" if -t STDIN;
+    # time waiting for the second and subsequent inputs
+    # should get assigned to the condition statement
+    # not the last statement executed in the loop
      while (<>) {
          chomp;
          last if not $_;
          1;
      }
  }
-
-# --- File::Find ---
-
-sub wanted {
-    return 1;
-}
-
-find( \&wanted, '.');

Modified: trunk/demo/demo-run.pl
==============================================================================
--- trunk/demo/demo-run.pl      (original)
+++ trunk/demo/demo-run.pl      Mon Dec  1 01:55:49 2008
@@ -1,20 +1,21 @@
  #!/bin/env perl -w
  use strict;
+use IO::Handle;

  my $NYTPROF = ($ENV{NYTPROF}) ? "$ENV{NYTPROF}:" : "";

  my %runs = (
      start_begin => {
          skip => 0,
-        NYTPROF => 'start=begin',
+        NYTPROF => 'start=begin:optimize=0',
      },
      start_check => {
-        skip => 0,
-        NYTPROF => 'start=init',
+        skip => 1,
+        NYTPROF => 'start=init:optimize=0',
      },
      start_end => {
-        skip => 0,
-        NYTPROF => 'start=end',
+        skip => 1,
+        NYTPROF => 'start=end:optimize=0',
      },
  );

@@ -25,8 +26,15 @@
      $ENV{NYTPROF}      = $NYTPROF . $runs{$run}{NYTPROF} || '';
      $ENV{NYTPROF_HTML} = $runs{$run}{NYTPROF_HTML} || '';

-    system("perl -Mblib -MDevel::NYTProf demo/demo-code.pl @ARGV") == 0
-        or exit 0;
+    my $cmd = "perl -d:NYTProf demo/demo-code.pl 100 1";
+    open my $fh, "| $cmd"
+        or die "Error starting $cmd\n";
+
+    $fh->autoflush;
+    print $fh "$_\n" for (1..10);
+    sleep 2;
+    print $fh "$_\n" for (1..10);
+    close $fh;

      my $outdir = "demo-out/profiler-$run";
      system("rm -rf $outdir") == 0 or exit 0;

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