/ Usr / বিন / টাইম শেল কমান্ডের সাহায্যে% e যথার্থতা বৃদ্ধি করুন


19

আমি যখন শেলটিতে টাইম কমান্ডটি চালিত করি তখন time ./myappনীচের মতো একটি আউটপুট পাই:

real    0m0.668s
user    0m0.112s
sys     0m0.028s

তবে, আমি যখন কমান্ডটি চালাচ্ছি তখন আমি \time -f %e ./myappনির্ভুলতা হারাব এবং আমি পেয়ে যাব:

2.01s

আমি যদি %Eকমান্ডটি ব্যবহার করি তবে আমিও একইভাবে নির্ভুলতা হারাব। আমি কীভাবে এটি আবার আরও নির্ভুলতার জন্য পরিবর্তন করব, তবে এখনও কেবলমাত্র কয়েক সেকেন্ড আউটপুট করা হচ্ছে?

আমি আমার গবেষণাকে এই লিনাক্স / ইউনিক্স কমান্ড: সময় এবং এই প্রশ্নের উপর ভিত্তি করেছিলাম

উত্তর:


21

আমি ধরে নিচ্ছি আপনি বুঝতে পেরেছেন যে এই দুটি কমান্ডই সময়ের ভিন্ন সংস্করণটি ডেকেছে, তাই না?

বাশের অন্তর্নির্মিত সংস্করণ

% time

জিএনইউ টাইম ওরফে , / Usr / বিন / সময়

% \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.

জিএনইউ time, /usr/bin/timeসাধারণত অন্তর্নির্মিতের চেয়ে বেশি কার্যকর।

আপনার যথার্থ সমস্যা হিসাবে এটি এখানে এই গিথুব গিস্টে আচ্ছাদিত রয়েছে , বিশেষত:

জিএনইউয়ের সময় কেন বাশ সময় আরও সঠিক?

বিল্টিন বাশ কমান্ড সময় কার্যকরভাবে মিলিসেকেন্ডের যথাযথতা দেয় এবং জিএনইউ সময় (সাধারণত / usr / বিন / সময়) শতভাগ সেকেন্ড দেয়। (2) সিস্কাল সময়গুলি ঘড়িতে সময় দেয় এবং 100 টি ঘড়ি = 1 সেকেন্ড (সাধারণত), সুতরাং নির্ভুলতা জিএনইউ সময়ের মতো। বাশ সময় কী ব্যবহার করা হয় যাতে এটি আরও সুনির্দিষ্ট হয়?

বাশ সময় অভ্যন্তরীণভাবে গেরুসেজ () ব্যবহার করে এবং জিএনইউ সময় বার () ব্যবহার করে। মাইক্রোসেকেন্ড রেজোলিউশনের কারণে 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

ভেরিয়েবলগুলিতে বাশ ম্যানুয়াল থেকে :

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.

হ্যাঁ আমি ইতিমধ্যে সমস্ত কিছু জানতাম। সুতরাং আমি সিদ্ধান্ত নিতে পারি যে আমি যা চাই তা অসম্ভব? বাশ সময়ের সংস্করণটি ব্যবহার করার এবং কেবল 3 সংখ্যার সাথে আসল সেকেন্ড সময় পাওয়ার কোনও উপায় আছে?
শিখা_ফিনিক্স

আমার আপডেট দেখুন, আপনি ভেরিয়েবল টাইমফর্ম্যাট ব্যবহার করে বাশের টাইম কমান্ড নিয়ন্ত্রণ করতে পারেন। আপনি কি এটি খুঁজছেন?
slm

ইয়াহ, এটাই, ধন্যবাদ! আমি ভাবছি যদিও, আমি কীভাবে এটি একটি ফাইলের সাথে যুক্ত করব? আমি% TIMEFORMAT = '% 3R' ব্যবহার করার চেষ্টা করছি; সময় (ঘুম .22222) >> bla.txt তবে এটি কাজ করছে না: এস যাই হোক, নির্বাচিত। যদি আমি তোমার কর্মফল ++, দিতে পারে, কিন্তু আমি 15 কর্মফল হবে না -.- '
Flame_Phoenix

2
TIMEFORMAT = '% 3R'; সময় (ঘুম .22222) 2 >> myFile.txt এটি পান!
শিখা_ফিনিক্স

উভয় দীর্ঘ সময় ব্যবহারকারীর এবং সম্পর্কে জানতাম না TIMEFORMAT, আমি সবসময় আসল সময় বের করার জন্য সেড ব্যবহার করি। ধন্যবাদ! "মাইক্রোসেকেন্ড রেজোলিউশনের কারণে।" বিবৃতি আমার আশা রাখে যা TIMEFORMAT=%6Rকাজ করবে তবে মনে হয় যে যথার্থ অঙ্কটি কেবলমাত্র 0-3 হতে পারে।
mxMLnkn
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.