資源簡介
matlab的功能函數(shù),屬于計時工具,
Copyright (c) 2010, The MathWorks, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
代碼片段和文件信息
function?[t?measurement_overhead?measurement_details]?=?timeit(f?num_outputs)
%TIMEIT?Measure?time?required?to?run?function.
%???T?=?TIMEIT(F)?measures?the?time?(in?seconds)?required?to?run?F?which?is?a
%???function?handle.??TIMEIT?calls?F?with?either?no?output?arguments?or?one
%???output?argument?depending?on?nargout(F).
%
%???T?=?TIMEIT(FN)?calls?F?with?N?output?arguments.??N?can?be?0?1?2?3?or?4.
%
%???TIMEIT?handles?automatically?the?usual?benchmarking?procedures?of?“warming
%???up“?F?figuring?out?how?many?times?to?repeat?F?in?a?timing?loop?etc.
%???TIMEIT?also?compensates?for?the?estimated?time-measurement?overhead
%???associated?with?tic/toc?and?with?calling?function?handles.??TIMEIT?returns
%???the?median?of?several?repeated?measurements.
%
%???Examples
%???--------
%???How?much?time?does?it?take?to?compute?sum(A.‘?.*?B?1)?where?A?is
%???12000-by-400?and?B?is?400-by-12000?
%
%???????A?=?rand(12000?400);
%???????B?=?rand(400?12000);
%???????f?=?@()?sum(A.‘?.*?B?1);
%???????timeit(f)
%
%???How?much?time?does?it?take?to?call?svd?with?three?output?arguments?
%
%???????X?=?[1?2;?3?4;?5?6;?7?8];
%???????f?=?@()?svd(X);
%???????timeit(f?3)
%
%???How?much?time?does?it?take?to?dilate?the?text.png?image?with
%???a?25-by-25?all-ones?structuring?element??(This?example?uses?Image?Processing
%???Toolbox?functions.)
%
%???????bw?=?imread(‘text.png‘);
%???????se?=?strel(ones(25?25));
%???????g?=?@()?imdilate(bw?se);
%???????timeit(g)
%???Steve?Eddins
%???Copyright?2008-2010?The?MathWorks?Inc.
if?nargin?2
????num_outputs?=?min(numOutputs(f)?1);
else
????if?num_outputs?>?4
????????warning(‘MATLAB:timeit:tooManyOutputs‘?...
????????????‘Too?many?function?output?arguments?specified.?timeit?will?call?your?function?with?4?output?arguments.‘);
????end
end
t_rough?=?roughEstimate(f?num_outputs);
%?Calculate?the?number?of?inner-loop?repetitions?so?that?the?inner?for-loop
%?takes?at?least?about?1ms?to?execute.
desired_inner_loop_time?=?0.001;
num_inner_iterations?=?max(ceil(desired_inner_loop_time?/?t_rough)?1);
%?Run?the?outer?loop?enough?times?to?give?a?reasonable?set?of?inputs?to?median.
num_outer_iterations?=?11;
%?If?the?estimated?running?time?for?the?timing?loops?is?too?long
%?reduce?the?number?of?outer?loop?iterations.
estimated_running_time?=?num_outer_iterations?*?num_inner_iterations?*?t_rough;
long_time?=?15;
min_outer_iterations?=?3;
if?estimated_running_time?>?long_time
????num_outer_iterations?=?ceil(long_time?/?(num_inner_iterations?*?t_rough));
????num_outer_iterations?=?max(num_outer_iterations?min_outer_iterations);
end
times?=?zeros(num_outer_iterations?1);
for?k?=?1:num_outer_iterations
????%?Coding?note:?An?earlier?version?of?this?code?constructed?an?“outputs“?cell
????%?array?which?was?used?in?comma-separated?form?for?the?left-hand?side?of
????%?the?call?to?f().??It?turned?out?though?that?the?comma-separated?output
????%?argument
- 上一篇:直方圖規(guī)格化
- 下一篇:max VR代理插件
評論
共有 條評論