Please, consider this generic piece of code:
for j = 0 to (Array.length myArray) - 1 do
if property.(id) then
(* do a bunch of stuff*)
done
Here, property
is a very large array of boolean.
In this experiment, we have 2 cases:
in the 1st,
property.(id)
is always true.In the second,
property.(id)
can be either true or false.
We want that the 2nd case win, since it skips code execution.
But this doesn't happen because of branch conditioning.
We have also tried partitioning property
instead of a if
statement, but the 1st case still wins.
(These are all suggestions by OCaml community members).
Our problem definition is: we can detect a property that allows us to skip part of the code. But using a large boolean array to save which element has this property makes the checking for the property itself slower than the saved code execution.
Thus, the question now is more general: what is the better way of implementing this problem?
We really appreciate any suggestion from the community.