[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: benchmarking m-file replacements
From: |
Rik |
Subject: |
Re: benchmarking m-file replacements |
Date: |
Thu, 21 Apr 2016 09:18:21 -0700 |
On 04/21/2016 07:25 AM, address@hidden wrote:
> Yes, maybe deprecation is no option at all then. But I think we should
> use the power of Octave, to make the code base as easy as possible, if
> the m-file does not result in a total performance penalty.
As long as there is no performance penalty, I am not opposed. But
benchmarking can definitely be difficult. I presented a talk at OctConf
2015 on improving m-file performance which talked briefly about some of the
pitfalls.
>
> tic; for i = 1:5, printf_m("%s", "hi everyone"); end, disp(toc)
> 6.3205e-04
For a small sample size like this the results are often skewed by the first
run through the loop where the printf_m function is parsed and placed in
the symbol table. To get around this, execute the function printf_m once
before calling the benchmark. Even so, small sample sizes usually don't
work because you may hit a window when other processes on your
computer--which can steal CPU cycles--are either more or less active.
Switching to cputime rather than the wall time measured by tic/toc can
help, but still does not completely eliminate the effect of background
processes.
> tic; for i = 1:5, printf("%s", "hi everyone"); end, disp(toc)
> 2.1100e-04
> tic; for i = 1:20000, printf_m("%s", "hi everyone"); end, disp(toc)
> 1.5331
> tic; for i = 1:20000, printf("%s", "hi everyone"); end, disp(toc)
> 1.5113
>
I benchmarked printf_m using the script below.
-- bmark.m script --
N = 1e4;
more off;
tic;
for i = 1:N
# printf ("Hello World\n");
printf_m ("Hello World\n");
endfor
bm = toc;
clc;
bm
-- End script --
The results were:
printf_m: .404
printf: .102
% change: +296%
> function numbytes = printf_m (varargin)
>
> if (nargin < 1)
> print_usage ();
> endif
>
> numbytes = fprintf (varargin{:});
>
> endfunction
>
printf does not return the number of bytes unless requested. I think you
may need something like this
nbytes = fprintf (varargin{:});
if (nargout > 0)
numbytes = nbytes;
endif
I didn't benchmark that, but it is likely to slow it down further.
--Rik
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: benchmarking m-file replacements,
Rik <=