3 ms·
You could use a while loop or recursion instead of a for loop. A couple of simple things I noticed is that the complexity of your functional code is higher than
by Dn_Ab 15y ago
You could use a while loop or recursion instead of a for loop. A couple of simple things I noticed is that the complexity of your functional code is higher than the imperative - it shows the speed of ocaml that it was able to get you so much performance.
Although, one way to give some advantage back to F# would be to parallelize your code. Last I checked F# allows you to do this more easily due to constructs like async and agents and .net parallel stuff and in a better way since OCaml has a GIL.
------------
List.map (abMinimax (not maximizeOrMinimize) (otherColor color) (depth-1))
|> List.map snd
iterates through the list twice. You could just as easily have removed the second List.map.
You can replace (map |> filter) with a fold.
allData |> List.sortBy getScore |> List.rev |> List.head
could sort by negative score. There are a couple other suggestions I could give to replace the use of reference cells and for loops with recursion, comprehensions, unfolds or folds. Some would not be speed improvements but would yield shorter more colloquial code. But I unfortunately can't afford to donate that time at the moment. Sorry I could not give more concrete advice.
- ttsiodras 15y agoI replaced the exceptions from the functional F# code with mutable flags and while loops - and its speed improved from being 6 times slower than OCaml, to being 5 times slower. I also replaced the sort with a fold... and there was no speed improvement (the lists are so small it made no difference). Oh well, what can you do? :-)