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

Add Base.format_bytes(; binary=false) option #50572

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ function padded_nonzero_print(value, str, always_print = true)
end
end

function format_bytes(bytes) # also used by InteractiveUtils
bytes, mb = prettyprint_getunits(bytes, length(_mem_units), Int64(1024))
function format_bytes(bytes; binary=true) # also used by InteractiveUtils
units = binary ? _mem_units : _cnt_units
factor = binary ? 1024 : 1000
bytes, mb = prettyprint_getunits(bytes, length(units), Int64(factor))
if mb == 1
return string(Int(bytes), " ", _mem_units[mb], bytes==1 ? "" : "s")
return string(Int(bytes), " ", units[mb], bytes==1 ? "" : "s")
else
return string(Ryu.writefixed(Float64(bytes), 3), " ", _mem_units[mb])
return string(Ryu.writefixed(Float64(bytes), 3), binary ? " $(units[mb])" : "$(units[mb])B")
end
end

Expand Down