[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bin2dec behavior different from Matlab?
From: |
Daniel J Sebald |
Subject: |
Re: bin2dec behavior different from Matlab? |
Date: |
Sat, 17 Mar 2012 05:29:21 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16 |
On 03/16/2012 10:15 PM, Daniel J Sebald wrote:
octave:19> tvec = char (randi ([48 49], 1e6, 10));
octave:20> tvec(randi(1e7, 1e6,1)) = " ";
octave:21> ctvec = cellstr(tvec);
octave:22>
octave:22> cpuzero = cputime();
octave:23> junk = bin2dec(tvec);
octave:24> cputime() - cpuzero
ans = 423.04
octave:25>
octave:25> cpuzero = cputime();
octave:26> junk = test_bin2dec(ctvec);
octave:27> cputime() - cpuzero
ans = 68.398
So two questions come to mind from this:
1) The cellfun() based approach is five times faster than the version
3.2.4 approach (granted, I left out several things), and the conversion
ctvec = cellstr(tvec) is relatively fast compared to these benchmark
times so maybe converting to a cell array approach is better. (John's
point I believe.) There may be a better approach than the power()
routine, but I was just trying to illustrate cellfun().
2) What machine are you using that is so fast?!
I had the vector backward in my little routine, anyway...
OK, now I'm getting in tune here. The 3.2.4 bin2dec uses looping so it
is no wonder the it takes 423 seconds. I downloaded just the bin2dec()
and base2dec() scripts and now get an amazing speed up to 1.6 seconds. Wow.
Well, that leads to the question, Why is cellfun() so noticeably slow?
Is it just in 3.2.4 that cellfun() is slow? John, any reason that
something like
function retval = test_bin2dec (d)
retval = cellfun('binchar2dec', d);
endfunction
function retval = binchar2dec(s)
s = s(!isspace(s));
retval = (s-'0')*(2.^[length(s)-1:-1:0])';
endfunction
runs about 40 times slower than the matrix multiply method Rik is using?
I'm thinking, sure it might be slower, but by a factor of two or
three, not 40.
cellstr() would fall in this category too. That takes 1.0 second. I
understand that the code is creating cells and there is memory
allocation, but the thing about cellstr() is that we know the input is a
string of a fixed length for *all* the cells so internally cells could
be created with one big hunk of memory. All the cells look the same
except for a different string. cell2str should be fast too.
Sorry if I've missed something with being stuck on 3.2.4 still.
Dan
- Re: bin2dec behavior different from Matlab?, (continued)
- Re: bin2dec behavior different from Matlab?, Rik, 2012/03/16
- Re: bin2dec behavior different from Matlab?, John W. Eaton, 2012/03/16
- Re: bin2dec behavior different from Matlab?, Rik, 2012/03/16
- Re: bin2dec behavior different from Matlab?, Daniel J Sebald, 2012/03/16
- Re: bin2dec behavior different from Matlab?, Rik, 2012/03/16
- Re: bin2dec behavior different from Matlab?, Daniel J Sebald, 2012/03/16
- Re: bin2dec behavior different from Matlab?,
Daniel J Sebald <=
- Re: bin2dec behavior different from Matlab?, Jordi GutiƩrrez Hermoso, 2012/03/17
- Re: bin2dec behavior different from Matlab?, Daniel J Sebald, 2012/03/17
- Re: bin2dec behavior different from Matlab?, Daniel J Sebald, 2012/03/17
- Re: bin2dec and cellfun improvements, Rik, 2012/03/18
- Re: bin2dec and cellfun improvements, Daniel J Sebald, 2012/03/18
- Re: bin2dec and cellfun improvements, Daniel J Sebald, 2012/03/20
- Re: bin2dec behavior different from Matlab?, Daniel J Sebald, 2012/03/16
Re: bin2dec behavior different from Matlab?, ahowe42, 2012/03/22