App-QuoteCC
view release on metacpan or search on metacpan
lib/App/QuoteCC.pm view on Meta::CPAN
curl http://v.nix.is/~failo/quotes.yml | quotecc -i - -I YAML -o - -O C | gcc -x c -o failo-wisdom -
curl http://www.trout.me.uk/quotes.txt | quotecc -i - -I Fortune -o - -O C | gcc -x c -o perl-wisdom -
Or to a fast stand-alone minimal Perl script:
curl http://v.nix.is/~failo/quotes.yml | quotecc -i - -I YAML -o failo-wisdom.pl -O Perl
curl http://www.trout.me.uk/quotes.txt | quotecc -i - -I Fortune -o perl-wisdom.pl -O Perl
See how small they are:
$ du -sh *-wisdom*
56K failo-wisdom
44K failo-wisdom.pl
80K perl-wisdom
76K perl-wisdom.pl
Emit a random quote with the C program:
time (./failo-wisdom && ./perl-wisdom)
Support Batman - vote for the British National Party
< dha> Now all I have to do is learn php
<@sungo> it's easy.
<@sungo> take your perl knowledge. now smash it against child pornography
real 0m0.004s
user 0m0.000s
sys 0m0.008s
Or with the Perl program:
$ time (perl failo-wisdom.pl && perl perl-wisdom.pl)
I just see foreign words like private public static void feces implements shit extending penis
<@pndc> Imagine if cleaners were treated like sysadmins. "I've just
pissed all over the office floor; it's the cleaner's fault."
real 0m0.022s
user 0m0.012s
sys 0m0.004s
Emit all quotes:
./failo-wisdom --all > /tmp/quotes.txt
Emit quotes to interactive shells on login, in F</etc/profile>:
# spread failo's wisdom to interactive shells
if [[ $- == *i* ]] ; then
failo-wisdom
fi
=head1 DESCRIPTION
I wrote this program because using L<fortune(1)> and Perl in
F</etc/profile> to emit a random quote on login was too slow. On my
system L<fortune(1)> can take ~100 ms from a cold start, although
subsequent invocations when it's in cache are ~10-20 ms.
Similarly using Perl is also slow, this is in the 80 ms range:
perl -COEL -MYAML::XS=LoadFile -E'@q = @{ LoadFile("/path/to/quotes.yml") }; @q && say $q[rand @q]'
Either way, when you have a 40 ms ping time to the remote machine
showing that quote is the major noticeable delay when you do I<ssh
machine>.
L<quotecc> solves that problem, showing a quote takes around 4 ms
now. That's comparable with any hello wold program in C that I
produce.
=head1 AUTHOR
E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>
=head1 LICENSE AND COPYRIGHT
Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>
This program is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
( run in 1.129 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )