Skip to content

Instantly share code, notes, and snippets.

@jsks
Created July 17, 2015 12:01
Show Gist options
  • Save jsks/fef55f5a0f451e7cc99c to your computer and use it in GitHub Desktop.
Save jsks/fef55f5a0f451e7cc99c to your computer and use it in GitHub Desktop.
#!/bin/zsh
function read1 {
local i
local FILE
FILE=$(<$BFILE)
for i in ${(f@)FILE}; do
print $i
done
}
function read2 {
zmodload zsh/mapfile
local i
local -a FILE
FILE=(${(f@)mapfile[$BFILE]})
for i in ${FILE[@]}; do
print $i
done
}
function read3 {
zmodload zsh/system
local i
local buff
while sysread buff; do
for i in ${(f)buff}; do
print -- "$i"
done
done < $BFILE
}
function read4 {
zmodload zsh/system
local i
local FILE
FILE=$(<$BFILE)
while sysread buff; do
for i in ${(f)buff}; do
print -- "$i"
done
done <<< $FILE
}
function read5 {
local line
while read line; do
print $line
done < $BFILE
}
BFILE="bench.txt"
: > $BFILE
integer fd
exec {fd}>>$BFILE
for i in {1..30000}; print -u $fd "lorem ipsum"
time (for i in {1..10}; read1 >/dev/null)
time (for i in {1..10}; read2 >/dev/null)
time (for i in {1..10}; read3 >/dev/null)
time (for i in {1..10}; read4 >/dev/null)
time (for i in {1..10}; read5 >/dev/null)
exec {fd}>&-; rm bench.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment