Увеличьте %e точность с командой оболочки/usr/bin/time

Только, чтобы удостовериться, что Ваше терминальное кодирование установлено использовать UTF-8, можно выполнить следующую команду:

locale charmap  # UTF-8
19
13.04.2017, 15:36
1 ответ

Я предполагаю, что Вы понимаете, что обе этих команды называют другую версию времени, правильно?

встроенная версия удара

% time

Время GNU иначе./usr/bin/time

% \time

Встроенное time команда к bash может быть считан на здесь:

% help time
time: time [-p] PIPELINE
    Execute PIPELINE and print a summary of the real time, user CPU time,
    and system CPU time spent executing PIPELINE when it terminates.
    The return status is the return status of PIPELINE.  The `-p' option
    prints the timing summary in a slightly different format.  This uses
    the value of the TIMEFORMAT variable as the output format.

GNU time, /usr/bin/time, обычно более полезно, чем встроенное.

Относительно Вашей проблемы точности это покрыто здесь в этой сути GitHub, конкретно:

Почему время удар, более точный затем время GNU?

Встроенное время команды удара дает точность миллисекунды выполнения, и время GNU (обычно/usr/bin/time) дает точность сотой доли секунды. Времена (2) syscall дает времена в часах и 100 часах = 1 секунда (обычно), таким образом, точность похожа на время GNU. Что время удар с помощью то, так, чтобы это было более точно?

Время Bash внутренне использует getrusage (), и время GNU использует времена (). getrusage () намного более точен из-за разрешения микросекунды.

Вы видите сотые доли секунды со следующим примером (см. 5-ю строку вывода):

% /usr/bin/time -v sleep .22222
    Command being timed: "sleep .22222"
    User time (seconds): 0.00
    System time (seconds): 0.00
    Percent of CPU this job got: 0%
    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.22
    Average shared text size (kbytes): 0
    Average unshared data size (kbytes): 0
    Average stack size (kbytes): 0
    Average total size (kbytes): 0
    Maximum resident set size (kbytes): 1968
    Average resident set size (kbytes): 0
    Major (requiring I/O) page faults: 0
    Minor (reclaiming a frame) page faults: 153
    Voluntary context switches: 2
    Involuntary context switches: 1
    Swaps: 0
    File system inputs: 0
    File system outputs: 0
    Socket messages sent: 0
    Socket messages received: 0
    Signals delivered: 0
    Page size (bytes): 4096
    Exit status: 0

Больше разрешения может иметься с помощью удара time управляйте как так, и можно управлять разрешением:

# 3 places 
% TIMEFORMAT='%3R'; time ( sleep .22222 )
0.224

Из руководства Bash по переменным:

TIMEFORMAT
The value of this parameter is used as a format string specifying how the timing information for pipelines prefixed with the time reserved word should be displayed. The ‘%’ character introduces an escape sequence that is expanded to a time value or other information. The escape sequences and their meanings are as follows; the braces denote optional portions.

%%
A literal ‘%’.

%[p][l]R
The elapsed time in seconds.

%[p][l]U
The number of CPU seconds spent in user mode.

%[p][l]S
The number of CPU seconds spent in system mode.

%P
The CPU percentage, computed as (%U + %S) / %R.

The optional p is a digit specifying the precision, the number of fractional digits after a decimal point. A value of 0 causes no decimal point or fraction to be output. At most three places after the decimal point may be specified; values of p greater than 3 are changed to 3. If p is not specified, the value 3 is used.

The optional l specifies a longer format, including minutes, of the form MMmSS.FFs. The value of p determines whether or not the fraction is included.

If this variable is not set, Bash acts as if it had the value

$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'
If the value is null, no timing information is displayed. A trailing newline is added when the format string is displayed.
22
27.01.2020, 19:45
  • 1
    да я уже знал все это. Таким образом, я могу прийти к заключению, что то, что я хочу, невозможно? Существует ли способ использовать версию времени удара и только получить реальное secs время с 3 цифрами? –  Flame_Phoenix 31.03.2013, 04:48
  • 2
    Посмотрите мое обновление, можно управлять командой времени удара с помощью переменного TIMEFORMAT. Это то, что Вы ищете? –  slm♦ 31.03.2013, 05:31
  • 3
    Yah, вот именно, Спасибо! я задаюсь вопросом, хотя, как я добавляю это в файл? Я пытаюсь использовать % TIMEFORMAT = '% 3R'; время (спят.22222),>> bla.txt, но оно не работает :S Так или иначе, выбранный. Мне бы хотелось дать Вам карму ++, но у меня нет 15 карм-.-' –  Flame_Phoenix 31.03.2013, 14:27
  • 4
    TIMEFORMAT = '% 3R'; время (сон.22222) 2>>myFile.txt ПОЛУЧИЛО его! –  Flame_Phoenix 31.03.2013, 14:36

Теги

Похожие вопросы