⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch39_02.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 39] 39.2 Timing Programs </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:50:10Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch39_01.htm"TITLE="39. Time and Performance"><LINKREL="prev"HREF="ch39_01.htm"TITLE="39.1 Which Time Is It? "><LINKREL="next"HREF="ch39_03.htm"TITLE="39.3 The csh time variable "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_01.htm"TITLE="39.1 Which Time Is It? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 39.1 Which Time Is It? "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 39<BR>Time and Performance</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_03.htm"TITLE="39.3 The csh time variable "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 39.3 The csh time variable "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0073">39.2 Timing Programs </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43506"></A><ACLASS="indexterm"NAME="AUTOID-43508"></A><ACLASS="indexterm"NAME="AUTOID-43510"></A><ACLASS="indexterm"NAME="AUTOID-43512"></A>Two commands, <EMCLASS="emphasis">time</EM> and <EMCLASS="emphasis">/bin/time</EM>, provide simple timings.Their information is highly accurate, because no profiling overheaddistorts the program's performance. Neither programprovides any analysis on the routine or trace level. They report thetotal execution time, some other global statistics, and nothing more.You can use them on any program.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43518"></A><EMCLASS="emphasis">time</EM> and <EMCLASS="emphasis">/bin/time</EM> differ primarily in that <EMCLASS="emphasis">time</EM> isbuilt into the C shell. Therefore, it cannot be used in Bourne shell scriptsor in makefiles. It also cannot be used if you prefer the Bourneshell (<EMCLASS="emphasis">sh</EM>).<EMCLASS="emphasis">/bin/time</EM> is an independent executable fileand therefore can be used in any situation. To get a simple program timing, enter either <EMCLASS="emphasis">time</EM> or <EMCLASS="emphasis">/bin/time</EM>, followed by the command you would normally useto execute the program. For example, to time a program named <EMCLASS="emphasis">analyze</EM>, enter the following command:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>time analyze inputdata outputfile</B></CODE>9.0u 6.7s 0:30 18% 23+24k 285+148io 625pf+0w</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43533"></A><ACLASS="indexterm"NAME="AUTOID-43535"></A><ACLASS="indexterm"NAME="AUTOID-43538"></A><ACLASS="indexterm"NAME="AUTOID-43540"></A>This indicates that the program spent 9.0 seconds on behalf of theuser (user time), 6.7 seconds on behalf of the system (systemtime, or time spent executing UNIX kernel routines on the user'sbehalf), and a total of 30 seconds elapsed time. Elapsed time is thewall clock time from the moment you enter the command until it terminates, including time spent waiting for other users, I/O time, etc. </P><PCLASS="para">By definition, the elapsed time is greater than your total CPU time and can even be several times larger. You can set programs to be timed automatically (without typing <EMCLASS="emphasis">time</EM>first) or change the output format by setting the <EMCLASS="emphasis">csh</EM> <SPANCLASS="link"><EMCLASS="emphasis">time</EM> variable (<ACLASS="linkend"HREF="ch39_03.htm"TITLE="The csh time variable ">39.3</A>)</SPAN>.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43548"></A>The example above shows the CPU time as a percentage of the elapsed time(18&nbsp;percent). The remaining data report virtual memory management and I/O statistics. The meaning varies, depending on your shell; check youronline <EMCLASS="emphasis">csh</EM> manual page or article<ACLASS="xref"HREF="ch39_03.htm"TITLE="The csh time variable ">39.3</A>.</P><PCLASS="para">In this example, under SunOS 4.1.1, the other fields show the amount ofshared memory used, the amount of nonshared memory used (<CODECLASS="literal">k</CODE>), the number of block input and output operations (<CODECLASS="literal">io</CODE>), and the number of page faults plus the number of swaps (<CODECLASS="literal">pf</CODE> and <CODECLASS="literal">w</CODE>).The memory management figures are unreliable in many implementations, so take them with a grain of salt.</P><PCLASS="para"><EMCLASS="emphasis">/bin/time</EM> reports only the real time (elapsed time), usertime, and system time. For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>/bin/time analyze inputdata outputfile</B></CODE>       60.8 real        11.4 user         4.6 sys</PRE></BLOCKQUOTE></P><PCLASS="para">[If you use the Bourne shell, you can just type <CODECLASS="literal">time</CODE>. <EMCLASS="emphasis">-JP</EM>&nbsp;]This reports that the program ran for 60.8 seconds before terminating,using 11.4 seconds of user time and 4.6 seconds of system time, for a total of 16 seconds of CPU time.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43566"></A>There's a third timer on many systems: <EMCLASS="emphasis">timex</EM>.It can give much more detail if your system has process accountingenabled.Check the <EMCLASS="emphasis">timex</EM>(1) manpage.</P><PCLASS="para">Article<ACLASS="xref"HREF="ch39_05.htm"TITLE="Why Is the System So Slow? ">39.5</A>has more about the terms used in this article.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN> <SPANCLASS="bibliomisc">from O'Reilly &amp; Associates' <CITECLASS="citetitle">UNIX for FORTRAN Programmers</CITE>, Chapter 8</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_01.htm"TITLE="39.1 Which Time Is It? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 39.1 Which Time Is It? "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_03.htm"TITLE="39.3 The csh time variable "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 39.3 The csh time variable "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">39.1 Which Time Is It? </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">39.3 The csh time variable </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -