-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Suggestion, Implement "time" #117
Comments
time should not be implemented, because it's a system util |
I can say it's built-in in bash. But, found package in gentoo too, so I guess that's fine. |
I think @etu might be onto something. As far as I can tell, the
The |
It would be nice for this to work, but that requires making a builtin |
👍 |
If you need to time fish functions:
|
Yes, that probably works. But does not produce a fair result. Because launching another instance of the shell means overhead. So in theory, timing of all fish-functions would be equally slow (if you can trust that fish always takes the same time to launch). Which might not be true since we all do have different configs, different hardware, and stuff. I for instance set my own $PATH in fish-config, which not only sets a variable, it also checks for duplicates in the variable, and so on. We would have a better result with better performance if we had a builtin for it. And @uggedal, Your hack is a fine hack, so I rewrote my function "time" to use it. I made a function because I always want -p on the command to be there.
|
Because time is... well, time-sensitive, having a builtin for it might actually make sense. That conceptually works but has some overhead in loading another fish process. |
+1 on this. Not being able to accurately time builtin functions is frustrating |
👍 I'd love it for making my complicated prompt functions faster |
The custom time function that wrap the /usr/bin/time is not a good solution for me. It creates a new shell that does not have the current environment. Hence certain types of command will fail. For example, a python script that is running from a virtualenv. |
I've been using fish for a month and haven't needed it, but when I needed it today it was frustrating not having it. Another +1 for a built-in time. |
We can probably leverage the existing profiling support to make for a really awesome version of time. |
I think using the actual time program coincides with fish's design principles and should probably not be changed. |
@nanthiel can you explain what you mean? Which design principle? I'm also in favour of a built-in time command, in the mean time I'll use the wrapper function. |
@nanthiel: This particular design principle you refer to (the law of minimalism) doesn't exist since 2.0.0 (since I complained about adding as But I think "the law of minimalism" should be considered anyway. The reason for it being removed is allowing the built-ins to be implemented for performance reasons. Except I'm not sure how it applies to |
@xfix: Sorry, I wasn't aware of the principle change. I do agree |
👍 $ which time
/usr/bin/time
$ alias foo ls
$ time foo
foo: No such file or directory
0.00 real 0.00 user 0.00 sys This works fine in bash as others have stated. |
AFAICT, the wrapper doesn't work for fish functions that aren't defined in the shell config. That means that I can't time functions that are only in the current shell. So another 👍 from me to have it be builtin that is capable of running functions. |
FWIW, I agree with @ridiculousfish that
The |
This is already implemented: sleep 10
echo $CMD_DURATION
The issue can be closed ... |
It seems like this should work but doesn't:
For some reason |
Nowadays I mostly use:
and run it after the command is completed. This assumes 2.2.0 or newer to work well. So my need for this is kinda dead. ltime of course stands for "last time" or something like that. |
AFIK : pensive : |
@bucaran: Yeah, that it doesn't include fish's startup time. Remember that fish always sources all of its configuration files. Like @krader1961 noticed "$CMD_DURATION" is updated too late (which means you always need to check it after the next prompt, as a separate command), but that might not be unfixable. But a much more awesome solution here would be what has already been proposed - a way to get our already existing profile stuff and apply it only to a certain command, e.g.
And then |
Shameless plug: I made a fish-command-timer plugin to do this - it makes fish print out the execution time of each command line. Please feel free to check it out! |
So, starting from some of @jichu4n's earlier code (before he switched function realtime
set -l command_start_time (date '+%s%N')
eval (string escape $argv)
set -l command_end_time (date '+%s%N')
set -l command_duration (math "$command_end_time - $command_start_time")
set -l minutes (math "$command_duration / 60000000000")
set -l seconds (math "$command_duration % 60000000000 / 1000000000")
set -l milliseconds (math "$command_duration % 1000000000 / 1000000")
printf '\nreal\t%dm%d.%03ds\n' $minutes $seconds $milliseconds
end It only tells you the "real" time (wall clock time) of the given command, not the user or system CPU time like bash's The big advantage over Regardless, I think the idea of a built-in command utilizing the existing profiling support is a very good idea; it's the only way we'd be able to get accurate insight into something like user/system CPU time, and it could easily give us more information too. |
Is it possible to make We could even make Using three variables Another option is to replace |
My system didn't have subsecond options for the date command, so I edited @whitelynx's script. Also added exit status and printed the result to stderr: function realtime
set -l start (date '+%s')
eval (string escape $argv)
set -l _status $status
set -l stop (date '+%s')
set -l duration (math "$stop - $start")
set -l minutes (math "$duration / 60")
set -l seconds (math "$duration % 60")
printf 'real\t%dm%ds\n' $minutes $seconds 1>&2
return $_status
end |
That script does not appear to work with command line arguments:
I am using Fish Shell version 2.6.0. |
Change |
This has now been implemented in e5e66ac. |
Is this a bug?
I'm running fish 3.10 btw. |
Like in bash:
The text was updated successfully, but these errors were encountered: