Last active
January 24, 2022 23:41
-
-
Save jul/f1b3fe9b0ec868fd4be33b53ba319cae to your computer and use it in GitHub Desktop.
timing python oneliner by size of line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export LANG=C | |
redadd() { python3 -c '(s,d,r)=(__import__("sys"),__import__("archery").mdict,__import__("functools").reduce);print(sorted(r(d.__add__,(d({l[:-1]:1}) for l in s.stdin.readlines())).items(),key=lambda k:k[1],reverse=True)[:10])' ; } | |
red() { python3 -c '(s,d,r)=(__import__("sys"),__import__("archery").mdict,__import__("functools").reduce);print(sorted(r(d.__radd__,(d({l[:-1]:1}) for l in s.stdin.readlines())).items(),key=lambda k:k[1],reverse=True)[:10])' ; } | |
function count() { python3 -c'(s,d)=(__import__("sys"),__import__("archery").mdict);print(sorted(sum((d({l[:-1]:1}) for l in s.stdin.readlines()),{}).items(),key=lambda k:k[1],reverse=True)[:10])'; } | |
cfl() { python3 -c'(s,t,d,f)=(__import__("sys"),__import__("tld"),__import__("archery").mdict,lambda l:t.get_fld(l[:-1],fix_protocol=True,fail_silently=True));print(sorted(sum((d({f(l):1}) for l in s.stdin.readlines()),{}).items(),key=lambda k:k[1],reverse=True)[:10])'; } | |
test_time() { | |
func="$1" | |
TIMEFORMAT="%U" | |
printf " %.5f" $( echo "$( (time $func < this.sample 1> /dev/null) 2>&1 ) / $l" | bc -l ); | |
} | |
OUT="out.$(date -Iminutes).png" | |
(echo line_count sum reduce redadd; | |
for((l=100; l<=3000; l+=500)); do | |
echo -n "$l"; head -n $l this.list > this.sample ; | |
test_time count;test_time red;test_time redadd; echo; | |
done ) | ( | |
cat > /dev/shm/mytempfile && \ | |
trap 'rm /dev/shm/mytempfile' EXIT && \ | |
#gnuplot -e "set terminal dumb; plot for[col=2:4] '/dev/shm/mytempfile' using 1:col title columnheader(col) with lines") | |
gnuplot -e "set terminal png; set output '${OUT}'; plot for[col=2:4] '/dev/shm/mytempfile' using 1:col title columnheader(col) with lines") && qiv $OUT | |
#redadd < this.list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Je crois que c'est pratique de pouvoir faire des oneliners rapides :)