You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 5133 Reporter:@Chris00 Assigned to:@alainfrisch Status: closed (set by @xavierleroy on 2017-02-16T14:18:34Z) Resolution: fixed Priority: normal Severity: feature Version: 3.13.0+dev Fixed in version: 4.03.0+dev / +beta1 Category: back end (clambda to assembly) Child of:#5204 Monitored by: "Pascal Cuoq" @ygrek@glondu eaburns @hcarty gildor @Chris00 pzimmer @alainfrisch@mmottl
Bug description
There have been a number of significant improvements in float handling in 3.12 but the following example shows on could go further:
Program 1 ------------------------------
let r = ref 0.0 in
for i = 0 to 1000_000_000 do r := float i done;
Printf.printf "%f\n" !r;
Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words
Program 2 ------------------------------
let r = ref 0.0 in
for i = 0 to 1000_000_000 do r := float i done;
Printf.printf "%f\n" (!r +. 0.);
Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words
The second version allocates much less and is way faster on my machine (Linux poincare 2.6.35 #1 SMP Fri Aug 20 14:34:25 CEST 2010 x86_64 GNU/Linux). Both programs were compiled to native code. It would be nice not to have to resort to such tricks to improve performance! Couldn't the compiler figure out this optimization?
The text was updated successfully, but these errors were encountered:
Indeed, this is a typical case where the boxing/unboxing strategy proposed in #5204 works nicely and avoids having to force manually the unboxing by adding an ad hoc "+. 0.".
Original bug ID: 5133
Reporter: @Chris00
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2017-02-16T14:18:34Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.13.0+dev
Fixed in version: 4.03.0+dev / +beta1
Category: back end (clambda to assembly)
Child of: #5204
Monitored by: "Pascal Cuoq" @ygrek @glondu eaburns @hcarty gildor @Chris00 pzimmer @alainfrisch @mmottl
Bug description
There have been a number of significant improvements in float handling in 3.12 but the following example shows on could go further:
Program 1 ------------------------------
let r = ref 0.0 in
for i = 0 to 1000_000_000 do r := float i done;
Printf.printf "%f\n" !r;
Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words
1000000000.000000
words: 2000000363.000000
2.79user 0.00system 0:02.79elapsed 99%CPU (0avgtext+0avgdata 4208maxresident)k
0inputs+0outputs (0major+313minor)pagefaults 0swaps
Program 2 ------------------------------
let r = ref 0.0 in
for i = 0 to 1000_000_000 do r := float i done;
Printf.printf "%f\n" (!r +. 0.);
Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words
1000000000.000000
words: 363.000000
1.20user 0.00system 0:01.20elapsed 99%CPU (0avgtext+0avgdata 3152maxresident)k
0inputs+0outputs (0major+247minor)pagefaults 0swaps
The second version allocates much less and is way faster on my machine (Linux poincare 2.6.35 #1 SMP Fri Aug 20 14:34:25 CEST 2010 x86_64 GNU/Linux). Both programs were compiled to native code. It would be nice not to have to resort to such tricks to improve performance! Couldn't the compiler figure out this optimization?
The text was updated successfully, but these errors were encountered: