[erlang-questions] Proper replacement for io_lib:format due to low speed
Chandru
chandrashekhar.mullaparthi@REDACTED
Sun Mar 22 11:10:18 CET 2015
Hi Max,
Is something like this not good enough in terms of speed?
iso8601({{Y,Mo,D}, {H,Mn,S}}) ->
list_to_binary([integer_to_list(Y), $-,
two_digit_str(Mo), $-,
two_digit_str(D), $T,
two_digit_str(H), $:,
two_digit_str(Mn), $:,
two_digit_str(S), $Z]).
two_digit_str(X) when X < 10 ->
[$0 | integer_to_list(X)];
two_digit_str(X) ->
integer_to_list(X).
cheers,
Chandru
On 22 March 2015 at 09:01, Max Lapshin <max.lapshin@REDACTED> wrote:
> Hi.
>
> I've met again performance problem with io_lib:format.
>
> iso8601({{Y,Mo,D}, {H,Mn,S}}) ->
> FmtStr = "~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0BZ",
> IsoStr = io_lib:format(FmtStr, [Y, Mo, D, H, Mn, S]),
> list_to_binary(IsoStr).
>
>
> Such code is a 0,01% of business logic of one small part of flussonic, but
> it takes about 95% of time to make 10% of text output.
>
>
> I've solved this problem via https://github.com/maxlapshin/io_libc but
> I'm not sure that it is
> a best way to do. Maybe this is better solved in pure erlang?
>
>
> Perhaps I'm not alone with this problem and somebody has some better idea
> than just exposing fprinf via nif?
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150322/5bcf12a6/attachment.htm>
More information about the erlang-questions
mailing list