-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Human readable formatting for numbers #6314
Human readable formatting for numbers #6314
Conversation
4b0bb61
to
5ddb877
Compare
5ddb877
to
afce539
Compare
Can this be in a |
@asterite methods dont affect compile times at all unless they are used. This method is unused unless you use the benchmark harness then you're doing a release build anyway and you don't care. |
@RX14 Almost: the parser still has to parse it and build an AST for it. Every bit counts. |
@asterite I don't think that extra tiny bit is worth the nuisance to have to require |
The
|
@r00ster91 this is not the place to discuss |
@straight-shoota Could you use descriptive commit messages for fixups? Just having |
544988a
to
387965d
Compare
@asterite The first line of the commit message needs to reference the targeted commit, otherwise |
Is |
@asterite if you use @straight-shoota You can refer to refspecs instead. see https://robots.thoughtbot.com/autosquashing-git-commits |
@yxhuvud That still doesn't allow custom descriptions in the first line of the commit message, does it? |
@straight-shoota Ah, no. That is a pity. |
@asterite it's not just a convention, it's an official part of git. |
@asterite judging by I'm entirely unconcerned by parse time. By the time parse time is the compiler bottleneck, we will have won. |
That's because At one point all parsing was done in Regardless, it's not just parsing time, it's holding the AST nodes in memory for the entire compilation. But yeah, let's not care. Let's wait for the magical solution that will enable incremental compilation :-) |
387965d
to
27afebd
Compare
@asterite I'm not saying compiler performance isn't useful, but this is picking the wrong thing to worry about. |
Sounds good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good, but I still think the IEC standard should be the default.
Another place where it would be possible to use this method is in HTTP::LogHandler
.
What do others think about IEC vs JEDEC? (see thread #6314 (comment)) |
7c8048d
to
e293aff
Compare
Will this make it into 0.27.1? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the number and string code to be in a humanize.cr
file in the std lib (even if it's included in the prelude). That would help to keep related code together.
@straight-shoota what do you think about organizing all the humanize code in a separate file/folder? |
@bcardiff he's on holiday... |
7435780
to
16d0306
Compare
@bcardiff done |
Hmm, seems that lately CI bugs increased in frequency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build error should go out after a rebase. But I would merge this with squash though. So GTG on my side.
The code looks better in the current layout. Thanks, @straight-shoota.
76f2ded
to
778579e
Compare
CI is still broken @bcardiff |
hmm, it's the same issue as in #7179. Lot's of |
Can those failing builds be reproduced? Are they using docker? If we can't reproduce these locally it'll be very hard to figure out what has gone wrong. And I'm almost sure it has nothing to do with a specific PR, I'm almost sure it's something about the CI (disk, memory?) |
The CRYSTAL_CACHE_DIR in the CI uses the Let's see if using the default location helps at both PRs. spoiler: it didn't work |
Usually |
It seems that the issue is not Running in CircleCI I don't know if it is something about the debug information itself or the file size or something with the memory buffers. That's all I could find. |
I suggest trying to run a debug build if the compiler with debug output (puts, after each .o is generated, check if the file is there later, etc.). Otherwise I don't know how can we debug this. |
* `Number#format`: Similar to `#to_s` but with more options for customizing the output format. Decimal separator and thousands delimiter can be specified (useful for localization) as well as the number of printed decimal places. * `Number#humanize`: Pretty prints the number in a human-readable format. Formats the most significant digits of the number with a prefix indicating the magnitude. Output parameters, prefixes etc. can be fully customized. * `Int#humanize_bytes`: Specialization of `Number#humanize` for binary units. ```cr 123.4567.format(decimal_places: 3) # => "123.457" 1_200_000_000.humanize # => "1.2G" 1536.humanize_bytes # => "1.5KiB" ```
778579e
to
0e8ba4b
Compare
Rebased and ready to ship. |
* 'master' of github.com:crystal-lang/crystal: Change the font-weight used in Playground (crystal-lang#7552) Fix formatting absolute paths (crystal-lang#7560) Refactor IO::Syscall as IO::Evented (crystal-lang#7505) YAML: fix test checking serialization of slices for libyaml 0.2.2 (crystal-lang#7555) Let Array#sort only use `<=>`, and let `<=>` return `nil` for partial comparability (crystal-lang#6611) Update `to_s` and `inspect` to have similar signatures accross the stdlib (crystal-lang#7528) Fix restriction of valid type vs free vars (crystal-lang#7536) Rewrite macro spec without executing a shell command (crystal-lang#6962) Suggest `next` when trying to break from captured block (crystal-lang#7406) Fix GenericClassType vs GenericClassInstanceType restrictions (crystal-lang#7537) Add human readable formatting for numbers (crystal-lang#6314) Add command and args to execvp error message (crystal-lang#7511) Implement Set#add? method (crystal-lang#7495)
This PR adds three methods for formatting numbers in human-readable formats:
Number#format
: Similar to#to_s
but allows customized separator and delimiter (useful for localization) and specifying the number of printed decimal places.Number#humanize
: Formats the most significant digits of the number with a prefix indicating the magnitude. Output parameters, prefixes etc. can be fully customized.Int#humanize_bytes
: Specialization ofNumber#humanize
for binary unitsNumber#humanize
is already put to use in the benchmark module.