Re: Big speed difference between styles?
- From: bart demoen <bmd@xxxxxxxxxxxxxx>
- Date: Mon, 18 Sep 2006 18:39:27 +0200
On Sat, 16 Sep 2006 03:46:06 -0700, roschler wrote:
I want to know what the performance difference is between the three
following styles of writing a predicate where I want to restrict the
domain of one of the arguments.
When you want to know something, and be (reasonably) sure you know
that you know something, it is worth conducting the experiment yourself.
Here is a program you can execute on your favourite Prolog system, and see
for yourself ...
The query is ?- t(1000000).
I will post results in different Prolog systems later. But only after you
have posted your results, and commented on them: do ut des.
Cheers
Bart Demoen
pred1(value_one).
pred1(value_two).
pred1(value_three).
pred2(X) :- (X == value_one ; X == value_two; X == value_three), !.
pred3(X) :- mmember(X, [value_one, value_two, value_three]), !.
pred4(_).
mmember(X,[X|_]).
mmember(X,[_|R]) :- mmember(X,R).
t(N) :-
statistics(runtime,[T1|_]),
do1(N),
statistics(runtime,[T2|_]),
T is T2 - T1,
write(method1 = T), nl, fail.
t(N) :-
statistics(runtime,[T1|_]),
do2(N),
statistics(runtime,[T2|_]),
T is T2 - T1,
write(method2 = T), nl, fail.
t(N) :-
statistics(runtime,[T1|_]),
do3(N),
statistics(runtime,[T2|_]),
T is T2 - T1,
write(method3 = T), nl, fail.
t(N) :-
statistics(runtime,[T1|_]),
do4(N),
statistics(runtime,[T2|_]),
T is T2 - T1,
write(dummy=T), nl, fail.
do1(N) :-
(N > 0 ->
pred1(value_one),
pred1(value_two),
pred1(value_three),
M is N - 1,
do1(M)
;
true
).
do2(N) :-
(N > 0 ->
pred2(value_one),
pred2(value_two),
pred2(value_three),
M is N - 1,
do2(M)
;
true
).
do3(N) :-
(N > 0 ->
pred3(value_one),
pred3(value_two),
pred3(value_three),
M is N - 1,
do3(M)
;
true
).
do4(N) :-
(N > 0 ->
pred4(value_one),
pred4(value_two),
pred4(value_three),
M is N - 1,
do4(M)
;
true
).
.
- References:
- Big speed difference between styles?
- From: roschler
- Big speed difference between styles?
- Prev by Date: Re: The n-knights problem
- Next by Date: Re: The n-knights problem
- Previous by thread: Re: Big speed difference between styles?
- Next by thread: Free Prolog libraries?
- Index(es):
Relevant Pages
|
|