use strict; use Config; $Config{useithreads} or die "Recompile Perl with threads to run this p +rogram."; use threads; use threads::shared; use Time::HiRes qw ( time sleep); our $starttime : shared; our $linecount : shared = 0; our $running : shared = 1; sub progress { my $lasttime = $starttime; my $lastlinecount = 0; sleep(1); $| = 1; do { my $now = time(); printf "\rline %d %8.1f avg lines per second %8.1f lines per s +econd", $linecount, $linecount/($now - $starttime), ($linecount - $la +stlinecount) / ($now - $lasttime); $lasttime = time(); $lastlinecount = $linecount; sleep(.5); } while ($running); }; $starttime = time(); our $thr1 = threads->new(\&progress); while (1) { $linecount++; last if $linecount > 9999; sleep(0.001); }; print "\n"; $running = 0; $thr1->join();
In reply to Re^2: Live operations-per-second counter
by gam3
in thread Live operations-per-second counter
by acidmax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |