My guess is that the performance difference does not come from using

1
Array.fold_left

per se.

1
Array.fold_left

should be almost as fast as a loop. Where I think the problem is is in the function passed to

1
Array.fold_left

. This function allocates 3 objects per iteration: 2 Coord2D and 1 Extent2D. So in total Extent will allocate 30003 objects whereas

1
ExtentIterative

will allocate only 3.

By on 6/6/2008 11:33 PM ()

indeed, but one always has the hope in a program written functionally that the compiler can recognize all these allocations are unnecessary and the original object can be side-effected to conserve memory. once it knows that, it might even be able to hold the four relevant values in registers, which is what i assume ultimately happens with the imperative loop. we assume, for instance, that the compiler is very smart about not allocating unnecessary tuples during a tail recursion.

By on 6/7/2008 11:07 AM ()

Yep, this kind of "localized" imperative programming can occasionally be needed with F#.

It goes without saying that you should generally only adjust code in this way once you have determined that a particular piece of code is the hot spot for an application. Functional first, imperative later. :-)

Kind regards

Don

By on 6/7/2008 11:25 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper