http://macenstein.com/default/archives/3069
Thanks for the distractions Noles 8=)
An orange in an apple orchard
http://macenstein.com/default/archives/3069
Thanks for the distractions Noles 8=)
who rewrote my work scheduler in brainfuck?
I have a strange sense of humour, lol.
what is it about some grown people, having to be baby sat :
another (big) section of the manual written, ENV processing, and an initial implementation for the history built-in among a few other things is done.
One interesting thing, usually sh only allows a single file in $ENV, and some versions of sh don’t even understand it period! In tpsh, as an interesting extension $ENV is treated like $PATH, in so far as ENV=/etc/tpshrc:/usr/local/etc/tpshrc:~/.tpshrc would cause tpsh to source an rc file in /etc, /usr/local/etc, and then the users home directory.
(Because of old OSes using drive letter:path like C:Windows, under such OS tpsh uses ‘;’ instead of ‘:’ to separate things like $PATH)
For some odd reason, I’m getting a notion that Term::ReadLine::Zoid is the only read line package for Perl, that isn’t fucked in the head >_>
the things I need out of life, never seem to be in the cards :. One thing I do know, I want tpsh to have profile/ENV and history support before nI pass out for the night; the only thing ot stand in the way is the usual miseries. Since the . and source built-in’s were implemented last night, and the ability to handle scripts some time back: doing a simple profile/ENV handling on startup is pretty easy now lol.
Really my head’s not very clear right now. I feel kind of like firing up doom-hr or wesnoth, but I’m not really in the mood for a game either 🙁
call: dproffpp -ap shift.pl
there are three sets of data, each meant to represent a small, medium, or large set. Each set is a list of words, 5, 25, and 100 words long respectively. (realistically the elements would average within 2 to 5 words inclusive). For simplicity N is 10.
There are 2 functions, xx and yy; representing different ways of solving the same problem: pretty printing the last N items of a given data set. In xx(), the set is reversed and then $#set -= N’d to clip all but the last N items, then reversed again to put it back into proper order. In yy() we avoid any reversals and just shift off the front of the list one at a time, until we reach N items left in the set. If the set contains less then N elements, no adjustment need be done.
Each function is called 3 times per iteration, once with each data set, over 3000 iterations (that’s 9000 calls to each function, or 3000 times with each set). The test was then executed 10 times.
The things so simple, it’s not important how long it takes to finish, but I’m interested in how big the the difference is between for (expr1; expr2; expr3) { shift @list } and $#list -= expr; and how much those two reversals hurt.
Every time, yy() ran faster by at least a half second. Then ran tests with xx() doing one reversal, then no reversals and yy() still beat it.
Now out of more curiosity, let’s see how larger data sets work. Each data set now contains 3 words instead of 1, and N is now 43; with the data sets being 5, 25, 100, 250, 500, and 1000 elements long.
A new function, zz() which is xx() without the reversals is also executed during the tests. After running the tests a short duration, it seems that the $#set -= N’ing is a bit faster, more so then the cost of the reversals.
here’s the new run down:
$ do_test() {
> local T=10
> while [ $T -gt 0 ]; do
> N=$1 dprofpp -ap shift.pl | tail -n 7 >> dp
> T=$(($T - 1))
> done
> }
$ for NUM in `builtin echo "3n10n43n51n227n"`; do do_test $NUM; done
The above (z)sh code will execute the test on shift.pl 10 times with an N of 3, 10, 43, 51, and then 227; appending the report (3 subs = (4+3) lines) to the file ‘dp’ for post-cpu meltdown review, otherwise we would have to take a look at all the I/O the tests generate before the report is printed by dprofpp.
Yes, I’m to damn lazy to use command history, let along retype the commands each time; why else would they have invented functions and loops 😛
About 15 minutes and 17 degrees Celsius later, some of the arithmetic involved finally caught up with my throbbing head.
Recap:
So that is what, maybe 2,700,000 function calls to &xx, &yy, and &zz; without counting the calls within those functions… and 846,000,000,000 list elements processed overall? After a little estimation based on the original data set/run time, I stopped counting after the estimated execution time passed 8 hours * X on this old laptop. Hmm, how’s that old saying go, curiosity fried the geeks cooling fan? lol.
I’m beginning to understand why some peoples workstations have like 32 ~ 64 GB of ECC RAM, and Symmetrical Multiple Processor (SMP) configurations to drool $! for, haha!
# message for commit 041a7343eb452b827dbd97a0c82c8538597f86f6:
#
# read built-in command implemented
sub read_bin {
my ($prmpt, $time);
my $line = "";
my @argv = @_;
my %opts = ( 'p=s' => $prmpt,
't=s' => $time,
'e' => sub { "no-op" },
);
do_getopt(@argv, %opts);
unless (@argv) {
warn "I can't read into thin air!";
return 0;
}
if ($prmpt and -t *STDIN) {
print $prmpt;
}
eval {
# remove custom die for ease of error check/report
local %SIG;
$SIG{__DIE__} = sub { die @_ };
$SIG{ALRM} = sub { die "timed-outn" };
if ($time) {
# an s, m, or h suffix causes sleep for sec, min, or hour
#
if ($time =~ /^(d*)([smh])/) {
if ($2 eq 's') {
$time = $1;
} elsif ($2 eq 'm') {
$time = $1 * 60;
} elsif ($2 eq 'h') {
$time = $1 * 3600;
} else {
warn "internal error on ", __LINE__;
# NOTREACHED
}
}
alarm $time;
}
chomp($line =);
alarm 0 if $time;
};
if ($@) {
warn $@ unless $@ eq "timed-outn";
# on time out, init the vars to empty strings
@ENV{@argv} = ('') x scalar @argv;
return 0;
} else {
# set each var to the words
#
# XXX because ifsplit has no notion of a &split 'LIMIT'
# if we used ifsplit here instead of a manual split,
# read x y
# foo bar ham
# would set $y to 'bar' instead of 'bar ham'
#
my $ifs = defined $ENV{IFS} ? qr/[$ENV{IFS}]/ : qr/s/;
@ENV{@argv} = grep !/^$/, split $ifs, $line, scalar(@argv);
return 1;
}
}
from the manual page updated in commit b1317d7e6e7f91b6c3a2650f44cd4f425e381d42 with message:
read built-in command documented
and blockquoted here using the pod2html output
- read [-p prompt] [-t timeout] variable …]
Read a line from standard input, split by fields, and assign each field to the indicated variables. If the number of variables is less then the number of fields, the remaining fields will be stored ‘as is’ in the last variable. If there are more variables then fields, the excess variables will be undefined. A prompt may be printed before reading input, by using the -p option. The -t option may be used to specify a timeout in which to abort the operation, should the user take their sweet time about pressing CR. The timeout value can take an optional
s
,m
, orh
suffix to denote seconds, minutes, or hours. If no suffix is given,s
will be assumed.
It’s not the greatest… but hey, I ain’t had any sleep since this mornings roll out… lol. It’ll do fine for an initial implementation, until I’ve actually got a functioning brain to deal with it 😛
Don’t worry about avoiding temptation — as you grow older, it starts
avoiding you.
— The Old Farmer’s Almanac
I wonder, if I’ll ever live to be that old lol.
Ok, not so surprising I slice ’round the corner, spot the X-Ray on the top of the stairs -> squeeze off a shot from my M16A2 on 3-round burst. Ok, no effect not even a flinch so 1ce more… 2ce more…. POW he shoots me.
The evil thing?
Trigger pulls -> 3×9 rounds should have been fired
Magazine -> 23/31 rounds remaining (on HUD)
Score board -> 8 rounds fired
the guy should have a least 7 holes in him, 9 if I didn’t hit the rail below the POI by some work of magic… but 8 rounds on the score board, with 0 hits to a slow tango rofl!!!!!