Created
November 16, 2016 01:19
-
-
Save anonymous/841f7594125243f3ea8e652524d073fa to your computer and use it in GitHub Desktop.
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
buf = Bytes.new 4096 | |
words = 1 | |
lines = 0 | |
bytes_total = 0 | |
nbytes = 0 | |
while (bytes = ARGF.read buf) > 0 | |
bytes_total += bytes | |
buf.each do |c| | |
nbytes += 1 | |
# this next line is what takes all the time | |
lines +=1 if c == 10 | |
end | |
end | |
# why are nbytes and bytes_total different? | |
# it looks like buf.each keeps going after the end... | |
puts [lines, nbytes, bytes_total] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment