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

Performance of %Ld formats #6577

vicuna opened this issue Sep 24, 2014 · 1 comment

Performance of %Ld formats #6577

vicuna opened this issue Sep 24, 2014 · 1 comment


Copy link

vicuna commented Sep 24, 2014

Original bug ID: 6577
Reporter: @alainfrisch
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2016-12-07T10:34:53Z)
Resolution: fixed
Priority: low
Severity: tweak
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: standard library

Bug description

My intuition was that with the new compile-time based implementation of format strings the following two lines would run at approximately the same speed:

ignore (Printf.sprintf "%Ld" x);
ignore (Printf.sprintf "%s" (Int64.to_string x));

However, some micro-benchmark indicates that the first one is about 33% slower than the second one. Same kind of observation for %ld, but not for %d.

This is not a big deal, but maybe some simple shortcuts for common boxed integer format specifiers could bring some non-negligible speedup.

I assume the performance hit comes from CamlinternalFormat.format_of_aconv. I'd try to specialize it to the three use cases (l, L, n) and always returns string literals, as format_of_iconv.

Copy link

vicuna commented Sep 24, 2014

Comment author: @alainfrisch

Fixed by commit 15319 on trunk. Also addressed performance of %S and %C in the two commits after that one.

@vicuna vicuna closed this as completed Dec 7, 2016
@vicuna vicuna added the stdlib label Mar 14, 2019
@vicuna vicuna added this to the 4.03.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants