"Nyeste Szabolcs" <infolist(a)citromail.hu> writes:
Sziasztok!
Próbálgattam az idõmérést Prologban, a statistics/2 függvénnyel, a következõ módon:
p(0) :- !.
p(N) :-
number(N),
N > 0,
N1 is N-1,
p(N1).
q(N,C) :-
statistics(runtime,[A|_]),
p(N),
statistics(runtime,[B|_]),
C is B-A.
q(C,10000000) esetén C 12000 körül volt mindig, gondolom millisecben mérve, azonban az
Enter leütésétõl a válasz megjelenéséig mindig kb 15 másodperc telt el. Mi ez a három mp
különbség? Gondolom a második statistics után már nincs sok dolga a rendszernek, vagy
mégis?
Nem tudom. Lehet pl. a szemetgyujtes (gc) ideje -- ami nem szamit bele a
runtime-ba. A fenti programnal szerintem ez csak akkor jon szoba, ha
konzultaltad es nem kompilaltad (ezt tetted?). De elvben mas, a gepeden
futo processzek is fogyaszthatnak idot.
A runtime mellett (ami a processz altal fogyasztott CPU ido, gc ill. stack
tologatasi ido nelkul), lekerdezheto meg a szemetgyujtes ideje es a faliora
ido (walltime), lasd alabb, ill a stack overflow kezelesre forditott ido
is. A statistics/0 hivas kiirja az osszes statisztikat.
q(N,(runtime:C, walltime:F, gctime:I)) :-
statistics(runtime,[A|_]),
statistics(walltime,[D|_]),
statistics(garbage_collection,[_,_,G]),
p(N),
statistics(runtime,[B|_]),
statistics(walltime,[E|_]),
statistics(garbage_collection,[_,_,H]),
C is B-A,
F is E-D,
I is H-G.
En a pnp.cs.bme.hu (eleg lassu) processzoron az alabbi, viszonylag
konzisztens idoket kapom (vedd eszre, hogy az interpretalt esetben
10-szer kisebb a ciklusok szama).
-Peter
---------------------------------------------------------------------------
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 8
model name : Pentium III (Coppermine)
stepping : 10
cpu MHz : 991.383
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr sse
bogomips : 1984.70
| ?- compile(user).
% compiling user...
| p(0) :- !.
p(N) :-
number(N),
N > 0,
N1 is N-1,
p(N1).
| |
% compiled user in module user, 0 msec -120 bytes
yes
| ?- q(10000000,C).
C = (runtime:1870,walltime:1870,gctime:0) ?
yes
| ?- q(10000000,C).
C = (runtime:1870,walltime:1870,gctime:0) ?
yes
| ?- q(10000000,C).
C = (runtime:1860,walltime:1870,gctime:0) ?
yes
| ?- [user].
% consulting user...
| p(0) :- !.
p(N) :-
number(N),
N > 0,
N1 is N-1,
p(N1).
| |
% consulted user in module user, 0 msec -40 bytes
yes
| ?- q(1000000,C).
C = (runtime:5020,walltime:6840,gctime:1790) ?
yes
| ?- q(1000000,C).
C = (runtime:5020,walltime:6830,gctime:1790) ?
yes
| ?- q(1000000,C).
C = (runtime:5100,walltime:6830,gctime:1710) ?
yes
| ?-