The exciting part for me is that the JIT compiler is currently far enough along to compile the loopy solution.
Input generationI used a simple script to generate some random input data. A double matrix is used, because JIT does not yet work for logical matrices.
function result = gen_test (n) result = double (rand (1, n) > .01); endfunction
VectorizedVectorized code (based off of code from the mailing list)
function z = vectorized (A, K) tic; temp = ones (1, K); z = conv (A, temp); z = z > K-1; z = conv (z, temp); z = z(K:end-K+1); z = z >= 1; toc; endfunction
I didn't do anything fancy here.
function z = loopy (A, K) tic;
z = A; n = numel (A); counter = 0; for ii=1:n if z(ii) counter = counter + 1; else if counter > 0 && counter < K z(ii-counter:ii-1) = 0; endif counter = 0; endif endfor if counter > 0 && counter < K z(end-counter+1:end) = 0; endif toc; endfunction
ResultsThese numbers were taken from a AMD FX(tm)-4100 Quad-Core Processor with 8 GB of RAM. I just ran each test once. For each test, the number of elements in A was 1,000,000.
|Vectorized||Loopy JIT||Loopy JIT (no overhead)||Loopy (No JIT)|
These results are expected. The efficiency of the vectorized approach depends on K, while the loopy version does not. While JIT support is not complete or stable yet1, I think this shows that the current JIT implementation is able to handle a few practical examples, not just interpreter benchmarks.
hg id for regular octave branch: 52cb71787cd1
hg id for jit branch: f649b66ef1af
1 Occasionally I break functionality like assignment, addition, and function calls.