Have you followed the code al the way down even into the C level code?
I use to use format/2,3 only when needed for outputing values as I thought it was time expensive. Then Jan W. noted in an unrelated reply that it was actually quite fast when used correctly and often used for more then just formatting, think conversion. After looking for examples in my list of trusted repositories I started to see many uses of format/2,3 beyond what I expected.
So donât take the name of a predicate or description of its use to be limited to just that. Also donât bring the baggage of ideas from imperative and functional languages along with you when reasoning about Prolog code, go look at the source.
If you want a predicate that is way beyond what it seems to be learn arg/3.
As I like to say, get the code working correctly before making it faster.
Did you notice the difference in lips? 33653791 vs 40645761.
I donât know if or how much that will skew the results but I would understand that more for such questions.
Sorry, but I could not catch the point, in particular why format/2 is related here. But I tested the comparison for curiosity, in which I havenât seen a significant difference.
?- time((between(0, 50_000_000, N), N > 49_000_000)).
% 98,000,005 inferences, 3.410 CPU in 3.423 seconds (100% CPU, 28739637 Lips)
N = 49000001 .
?- time((between(0, 50_000_000, N), compare(>, N, 49_000_000))).
% 98,000,003 inferences, 3.351 CPU in 3.362 seconds (100% CPU, 29243816 Lips)
N = 49000001 .
compare/3 examines the terms and sees which is less. It works on all kinds of terms, not just numbers. It doesnât perform arithmetic, just examines the internal representation. SWI-Prolog -- Manual
>/2 evaluates each terms using built-in arithmetic. It works on all terms that represent arithmetic expression.
For another timing on the list, load a file using swipl -O that holds
p(N) :-
between(0, 50_000_000, N),
N > 49_000_000.
and do ?- time(p(N)). That gives me the best time as it used optimized arithmetic done by the VM itself. All the others call a âforeignâ predicate. compare/3 is indeed standard order comparison and thus should be compared to @>/2, which -for me- is a little faster than compare/3.