JIT = Just In Time, i.e. the first time you use the code. On Mon, Sep 12, 2016 at 6:52 AM, MLicer <matjaz.li...@gmail.com> wrote:
> Indeed it does! I thought JIT compilation takes place prior to execution > of the script. Thanks so much, this makes sense now! > > Output: > first call: 0.804573 seconds (1.18 M allocations: 53.183 MB, 1.43% gc > time) > repeated call: 0.000472 seconds (217 allocations: 402.938 KB) > > Thanks again, > > Cheers! > > > On Monday, September 12, 2016 at 12:48:30 PM UTC+2, randm...@gmail.com > wrote: >> >> The Julia code takes 0.000535 seconds for me on the second run -- during >> the first run, Julia has to compile the method you're timing. Have a look >> at the performance tips >> <http://docs.julialang.org/en/latest/manual/performance-tips/#measure-performance-with-time-and-pay-attention-to-memory-allocation> >> for a more in depth explanation. >> >> Am Montag, 12. September 2016 11:53:01 UTC+2 schrieb MLicer: >>> >>> Dear all, >>> >>> i've written a low-pass filter in Julia and Python and the code in Julia >>> seems to be much slower (*0.800 sec in Julia vs 0.000 sec in Python*). >>> I *must* be coding ineffieciently, can anyone comment on the two codes >>> below? >>> >>> *Julia:* >>> >>> >>> <https://lh3.googleusercontent.com/-pEyZjPDcmP8/V9Z6hJdXKfI/AAAAAAAAKLc/iiefpFSzY88S333QndnbnnAnKUBQvzTkACLcB/s1600/filter_julia.png> >>> using PyPlot, DSP >>> >>> # generate data: >>> x = linspace(0,30,1e4) >>> sin_noise(arr) = sin(arr) + rand(length(arr)) >>> >>> # create filter: >>> designmethod = Butterworth(5) >>> ff = digitalfilter(Lowpass(0.02),designmethod) >>> @time yl = filtfilt(ff, sin_noise(x)) >>> >>> Python: >>> >>> from scipy import signal >>> import numpy as np >>> import cProfile, pstats >>> >>> def sin_noise(arr): >>> return np.sin(arr) + np.random.rand(len(arr)) >>> >>> def filterSignal(b,a,x): >>> return signal.filtfilt(b, a, x, axis=-1) >>> >>> def main(): >>> # generate data: >>> x = np.linspace(0,30,1e4) >>> y = sin_noise(x) >>> b, a = signal.butter(5, 0.02, "lowpass", analog=False) >>> ff = filterSignal(b,a,y) >>> >>> cProfile.runctx('filterSignal(b,a,y)',globals(),{'b':b,'a':a,'y':y}, >>> filename='profileStatistics') >>> >>> p = pstats.Stats('profileStatistics') >>> printFirstN = 5 >>> p.sort_stats('cumtime').print_stats(printFirstN) >>> >>> if __name__=="__main__": >>> main() >>> >>> >>> Thanks very much for any replies! >>> >>