[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Not even a profiler!!!
From: |
Fotios Kasolis |
Subject: |
Not even a profiler!!! |
Date: |
Wed, 8 Sep 2010 12:48:51 +0200 |
Are we interested in a function that simply uses tic toc to give time for every
line of a script (or sth similar). This is too simple and i think fine enough
to get an idea about bottlenecks. And some clever things could be done. Here is
a non clever example.
function [ ret ] = addTiming (fname)
if ~ strcmp (fname(end-1:end), ".m")
fname = [ fname, ".m" ];
endif
# Read file
fidin = fopen (fname, "r");
fidot = fopen ([ "timing_", fname ], "w");
stic = "tic;";
txt = 0; count = 1;
while txt ~= -1
txt = fgets (fidin);
if txt == -1 break endif
stoc = [ ", time(", num2str(count), ") = toc;" ];
str = [ stic, txt, stoc];
fputs (fidot, str);
count++;
endwhile
fclose (fidin);
fclose (fidot);
eval ([ "timing_", fname(1:end-2) ]);
bar (time);
xlabel ("Code line");
ylabel ("Time");
title ([ "Total time", num2str(sum(time)) ]);
system ([ "rm ", "timing_", fname ]);
endfunction
/Fotis
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Not even a profiler!!!,
Fotios Kasolis <=