[opensuse] Re: user/sys ticks for process exceed overall user/sys ticks
Linda Walsh wrote:
Peter Hofer wrote:
./ticks.py delta process: user: 2495 sys: 181 delta all: user: 2283 sys: 258
Despite the confusion regarding ticks vs. jiffies, I was curious what the same program woudl do in perl...
time python ticks.py delta process: user: 9263 sys: 2987 delta all: user: 6034 sys: 2178
67.35sec 92.64usr 29.89sys (181.94% cpu)
time perl /tmp/pticks delta process: user: 2917 sys: 3 delta all: user: 2926 sys: 25
3.36sec 29.20usr 0.03sys (870.05% cpu)
--- !!! The perl version is 20x faster as it uses the multiple cores.
For 9 threads:
lang #thrds #coresuse %efficency ---- ------ ------ ------- python 9 1.82 20.2% perl 9 8.70 96.7%
(2 CPU's @ 6 cores ea @ 1.6-2.8GHz using on-demand scheduler).
Source attached. I tried to use as close to same semantics as the python program. Even used python indentation where practical (I did split the prints at the end... something python seems to have problems with...)
#!/usr/bin/perl use 5.16.0; use threads; use P; sub open_for_read($) { open(my $handle, "<$_[0]") or die "opening $_[0]: $!"; $handle } sub ticks_all { my $f = open_for_read("/proc/stat"); return (split ' ', <$f>)[1,3] } sub ticks_process() { my $f = open_for_read("/proc/self/stat"); return (split ' ', <$f>)[13,14] } sub dowork () { use Digest::MD5; my $d = Digest::MD5->new; $d->add('nobody inspects'); $d->add(' the spammish repetition') for (0 .. 10_000_000)} my ($before_all_user, $before_all_sys) = ticks_all(); my ($before_process_user, $before_process_sys) = ticks_process(); my @threads; for my $i (0 .. 8) { my $t = threads->create(\&dowork); push @threads,$t } $_->join() foreach @threads; my ($after_all_user, $after_all_sys) = ticks_all(); my ($after_process_user, $after_process_sys) = ticks_process(); #(note: changing perl defaults for print) $, = " "; #put spaces between output fields $\ = "\n"; #add LF to end of lines by default print 'delta process: user:', $after_process_user - $before_process_user, ' sys:', $after_process_sys - $before_process_sys; print 'delta all: user:', $after_all_user - $before_all_user, ' sys: ', $after_all_sys - $before_all_sys;
participants (1)
-
Linda Walsh