digitalmars.D.learn - Converting an integer to a string with std.format.
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (3/3) Jan 06 2019 When converting a single integer to a string is `formatValue`
- Daniel Kozak (3/6) Jan 07 2019 I would go with std.conv.to or std.conv.text :)
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (8/9) Jan 07 2019 The reason for not using std.conv.to is to prevent the extra
- Vijay Nayar (9/12) Jan 07 2019 Also, if you do not need to write to a stream or a range and just
- Stefan Koch (7/10) Jan 07 2019 I've written my own itos function because using std.conv was too
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (2/6) Jan 07 2019 Thanks!
When converting a single integer to a string is `formatValue` preferred over `formattedWrite` in terms of compilation and run-time performance?
Jan 06 2019
I would go with std.conv.to or std.conv.text :) On Sun, Jan 6, 2019 at 10:55 PM Per Nordl=C3=B6w via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:When converting a single integer to a string is `formatValue` preferred over `formattedWrite` in terms of compilation and run-time performance?
Jan 07 2019
On Monday, 7 January 2019 at 09:57:45 UTC, Daniel Kozak wrote:I would go with std.conv.to or std.conv.text :)The reason for not using std.conv.to is to prevent the extra allocation needed in code such as sink.put(someIntegral.to!string) instead of something like sink.putIntegralAsString(someIntegral) which should only extend the memory buffer of `sink` (via at most one allocation or reallocation).
Jan 07 2019
On Sunday, 6 January 2019 at 21:53:31 UTC, Per Nordlöw wrote:When converting a single integer to a string is `formatValue` preferred over `formattedWrite` in terms of compilation and run-time performance?Also, if you do not need to write to a stream or a range and just need the value, `format("%s", value)` works as well as std.conv's `to!string(value)`. But between the two functions, it seems that the only difference is that `formattedWrite` only accepts the exact values that go on the output range (such as an integer), and `formatValue` has extra logic to convert structs, classes, and unions into strings by calling their `toString()` method.
Jan 07 2019
On Sunday, 6 January 2019 at 21:53:31 UTC, Per Nordlöw wrote:When converting a single integer to a string is `formatValue` preferred over `formattedWrite` in terms of compilation and run-time performance?I've written my own itos function because using std.conv was too expensive. see https://github.com/UplinkCoder/dmd/blob/newCTFE_reboot_20741/src/ctfe/bc_common.d#L95 if you do want to convert longs you'll need a bigger pow_table as well as a diffrent log10 function.
Jan 07 2019
On Monday, 7 January 2019 at 12:17:37 UTC, Stefan Koch wrote:I've written my own itos function because using std.conv was too expensive. see https://github.com/UplinkCoder/dmd/blob/newCTFE_reboot_20741/src/ctfe/bc_common.d#L95Thanks!
Jan 07 2019