Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meaning of time/1, extra choice point #378

Closed
UWN opened this issue Apr 20, 2020 · 5 comments
Closed

Meaning of time/1, extra choice point #378

UWN opened this issue Apr 20, 2020 · 5 comments

Comments

@UWN
Copy link

UWN commented Apr 20, 2020

?- 9=I,N is 2^I, time((true;true)),length(L,N).
   % CPU time: 0.000 seconds
   I = 9, L = [_A,_B,_C,_D,_E,_F,_G,_H,_I,_J|...], N = 512
;  % CPU time: 4.199 seconds
   I = 9, L = [_A,_B,_C,_D,_E,_F,_G,_H,_I,_J|...], N = 512
;  % CPU time: 8.396 seconds
   false.
?- time((true;true)).
   % CPU time: 0.000 seconds
   true
;  % CPU time: 0.019 seconds
   true
;  % CPU time: 0.040 seconds
   false.

There should not be a big difference between these two queries, as time/1 only measures (true;true). However, it seems that time/1 also includes the time spent in predicates thereafter and the top level loop which takes a lot with longer lists.

Further, time/1 adds an extra CP which changes performance substantially by retaining data that would otherwise be collected (in the long run, indeed)

@triska
Copy link
Contributor

triska commented Apr 20, 2020

The CP is due to format/2 using maplist/N, please see #192 for the core reason that should be addressed to resolve this once and for all, without ad hoc workarounds.

Resolved via #732!

triska added a commit to triska/scryer-prolog that referenced this issue Dec 19, 2020
…istic.

This works as soon as mthom#732 is merged, since then maplist/N and foldl/N
are deterministic in the required cases.

This also resolves the extra choicepoint of time/1 (see mthom#378).
triska added a commit to triska/scryer-prolog that referenced this issue Dec 19, 2020
…istic.

This works as soon as mthom#732 is merged, since then maplist/N and foldl/N
are deterministic in the required cases.

This also resolves the extra choicepoint of time/1 (see mthom#378).
triska added a commit to triska/scryer-prolog that referenced this issue Dec 19, 2020
…istic.

This works as soon as mthom#732 is merged, since then maplist/N and foldl/N
are deterministic in the required cases.

This also resolves the extra choicepoint of time/1 (see mthom#378).

Many thanks to @notoria for implementing better indexing in mthom#732,
which allowed me to find this opportunity for improvement!
@ghost
Copy link

ghost commented Dec 29, 2020

On Linux, the following happens:

$ scryer-prolog
?- use_module(library(time)).
   true.
?- time(sleep(2)).
   % CPU time: 0.000 seconds
   % CPU time: 0.001 seconds
   true.
?- halt
$ time -p scryer-prolog -g 'use_module(library(time))' -g 'sleep(2)' -g halt      
real 2.56
user 0.47
sys 0.08
$

Sleeping time isn't measured. What is time/1 measuring?

@triska
Copy link
Contributor

triska commented Dec 29, 2020

time/1 reports the CPU time, this is how long the CPU was active. sleep/1 suspends the process, so the CPU does nothing in that time (for that process).

The elapsed time is referred to as the "wall time".

@UWN
Copy link
Author

UWN commented Aug 20, 2021

?- time(true).
   % CPU time: 0.010 seconds
   % CPU time: 0.044 seconds
   true.

And what does the second time mean?

triska added a commit to triska/scryer-prolog that referenced this issue Nov 30, 2021
triska added a commit to triska/scryer-prolog that referenced this issue Nov 30, 2021
triska added a commit to triska/scryer-prolog that referenced this issue Nov 30, 2021
triska added a commit to triska/scryer-prolog that referenced this issue Nov 30, 2021
triska added a commit to triska/scryer-prolog that referenced this issue Nov 30, 2021
triska added a commit to triska/scryer-prolog that referenced this issue Nov 30, 2021
triska added a commit to triska/scryer-prolog that referenced this issue Nov 30, 2021
triska added a commit to triska/scryer-prolog that referenced this issue Dec 1, 2021
@triska
Copy link
Contributor

triska commented Dec 4, 2021

After ten thousand attempts, I think I resolved both issues!

Nested invocations of time/1 require correction of #1123. We currently have:

?- time(time(true)).
   % CPU time: 0.000 seconds
   % CPU time: 0.000 seconds
   true.
?- time(time(true)).
unexpected loop

Once #1123 is solved, this should also work with the present implementation of time/1.

@UWN UWN closed this as completed Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants