Пример эксперимента:
:- use_module(library(clpfd)).
:- use_module(library(lists)).
call_time(G,T) :-
statistics(runtime,[T0|_]),
G,
statistics(runtime,[T1|_]),
T is T1 - T0.
% Sorted has the same elements as List and is also sorted
clpfd_sort(List):-
same_length(List, Sorted),
chain(Sorted, #=<),
permutation(List, Sorted).
item_goal(I,clpfd_sort(I)).
n_randoms_times(NumberOfExperiments,Random_Lists,Times) :-
numlist(1,NumberOfExperiments,Experiment_Sizes),
maplist(numlist(1),Experiment_Sizes,ExperimentLists),
maplist(random_permutation,ExperimentLists,Random_Lists),
maplist(item_goal,Random_Lists,Goals),
maplist(call_time,Goals,Times).
Тест:
?- n_randoms_times(15,R,T),write(T).
[0,0,0,1,1,1,2,5,4,3,16,34,43,115,246]
Таким образом, время увеличивается, когда мы добавляем единицу к размеру списка ...