Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eof performance #8069

Closed
JeffBezanson opened this issue Aug 20, 2014 · 1 comment
Closed

eof performance #8069

JeffBezanson opened this issue Aug 20, 2014 · 1 comment
Labels
domain:io Involving the I/O subsystem: libuv, read, write, etc. performance Must go faster

Comments

@JeffBezanson
Copy link
Sponsor Member

From Don MacMillen on julia-dev:


   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0-dev+147 (2014-08-14 22:04 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 48eed79 (4 days old master)
|__/                   |  x86_64-linux-gnu

julia> io = open("ubuntu-14.04-desktop-amd64.iso")
IOStream(<file ubuntu-14.04-desktop-amd64.iso>)

julia> function readit(io)
           count = 0
           while !eof(io)
               ch = read(io, Uint8)
               count += 1
           end
           println("Bytes read: $count")
       end
readit (generic function with 1 method)

julia> @time readit(io)
Bytes read: 1010827264
elapsed time: 12.129340924 seconds (154348 bytes allocated)

julia> seekstart(io)
IOStream(<file ubuntu-14.04-desktop-amd64.iso>)

julia> @time readit(io)
Bytes read: 1010827264
elapsed time: 11.619949874 seconds (596 bytes allocated)

julia> seekstart(io)
IOStream(<file ubuntu-14.04-desktop-amd64.iso>)

julia> @time readit(io)
Bytes read: 1010827264
elapsed time: 11.881646789 seconds (596 bytes allocated)

julia> seekstart(io)
IOStream(<file ubuntu-14.04-desktop-amd64.iso>)

julia> function doread(io)
           count = 0
           fsize = getsize(io)
           while count < fsize
               ch = read(io, Uint8)
               count += 1
           end
           println("Bytes read: $count")
       end
doread (generic function with 1 method)

julia> function getsize(io)
           seekend(io)
           fsize = mark(io)
           seekstart(io)
           return fsize
       end
getsize (generic function with 1 method)

julia> @time doread(io)
Bytes read: 1010827264
elapsed time: 5.261891288 seconds (155772 bytes allocated)

julia> seekstart(io)
IOStream(<file ubuntu-14.04-desktop-amd64.iso>)

julia> @time doread(io)
Bytes read: 1010827264
elapsed time: 5.265442821 seconds (596 bytes allocated)
@JeffBezanson
Copy link
Sponsor Member Author

The times are much closer now. Beyond this I'm not sure it's possible to make eof as fast as integer comparison. Reading one byte at a time is not going to be super fast anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:io Involving the I/O subsystem: libuv, read, write, etc. performance Must go faster
Projects
None yet
Development

No branches or pull requests

1 participant