[Scilab-users] [EXTERNAL] Re: my loop faster than vectorization (???)
Rafael Guerra
jrafaelbguerra at hotmail.com
Fri Jun 30 19:20:11 CEST 2017
Hi,
For huge matrices of strings like your variable "b", eval() or evstr() do not seem to work efficiently in Scilab 5.5.2.
However, if you have a fast hard disk (SSD), it will be comparatively lightning fast to do the conversion via I/O functions such as:
csvWrite(b,"outb.csv");
c=csvRead("outb.csv");
Then use c in your code, which has now type of 'constant', with nor further need for eval/evstr.
Rgds,
Rafael
From: users [mailto:users-bounces at lists.scilab.org] On Behalf Of Carrico, Paul
Sent: Friday, June 30, 2017 12:46 PM
To: Users mailing list for Scilab <users at lists.scilab.org>
Subject: Re: [Scilab-users] [EXTERNAL] Re: my loop faster than vectorization (???)
Hi
Interesting feedback, but different of mine :)
With n=100000 with my working station under Windows 7.0 with Scilab 5.5.2
(from memory I noticed the same behavior on my old laptop under Ubuntu 16.04 LTS)
duration1 =
93.057
duration2 =
108.325
duration3 =
1.279
duration3 =
135.178
Nota: nevertheless for huge asci files containing millions of lines (not in the same format of course) , I finally decided to "outsource" this work
Paul
EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data
De : users [mailto:users-bounces at lists.scilab.org] De la part de Alexis Cros
Envoyé : vendredi 30 juin 2017 12:33
À : Users mailing list for Scilab
Objet : [EXTERNAL] Re: [Scilab-users] my loop faster than vectorization (???)
Hi,
On my computer came, in order of rapidity, 1st case, 2nd, 4th then 3rd
duration1 =
0.1907777
duration2 =
0.2304603
duration3 =
23.275328 wow!
duration4 =
0.2531153
We may compare who has the best computer ^^
Le 29/06/2017 à 09:56, Carrico, Paul a écrit :
Here is the correct code - loop faster here (68 time faster with n = 100 000)
I'm confuse
Paul
#############################################################
mode(0)
clear
n = 10000;
lower_bound = 0.1*n;
upper_bound = 0.6*n;
a = rand(n,1);
b = string(a);
// case 1 : eval on each row
tic();
i=1:(upper_bound-lower_bound+1)';
c(i,1) = zeros((upper_bound-lower_bound+1),1);
c(i,1) = eval(b(lower_bound:upper_bound,1));
duration1 = toc()
// case 2 : eval on the complete matrix
tic();
d = zeros((upper_bound-lower_bound+1),1);
d = string(d);
d = b(lower_bound:upper_bound,1);
d = eval(d);
duration2 = toc()
// case 3 :with an uggly loop
tic();
e = zeros((upper_bound-lower_bound+1),1);
for i = 1 : (upper_bound - lower_bound+1)
e(i,1) = eval(b(i+lower_bound-1,1));
end
duration3 = toc()
// case 4 :with an uggly loop (eval on the complete matrix)
tic();
f = zeros((upper_bound-lower_bound+1),1);
f = string(f);
for i = 1 : (upper_bound - lower_bound)
f(i,1) = b(i+lower_bound-1,1);
end
f = eval(f);
duration3 = toc()
EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data
De : users [mailto:users-bounces at lists.scilab.org] De la part de Carrico, Paul
Envoyé : jeudi 29 juin 2017 09:29
À : International users mailing list for Scilab. (users at lists.scilab.org<mailto:users at lists.scilab.org>)
Objet : [EXTERNAL] [Scilab-users] my loop faster than vectorization (???)
Hi all
I'm facing a case where a loop is faster than vectorization (at least I hope I'm using vectorization) ... I'm necessarily doing something wrong but I don't see what
Hope somebody will point out my mistake
Thanks for your time
Paul
################################################
mode(0)
clear
n = 10000;
lower_bound = 0.1*n;
upper_bound = 0.6*n;
a = rand(n,1);
b = string(a);
// case 1 : eval on each row
tic();
c = zeros((upper_bound-lower_bound),1);
c(1:(upper_bound-lower_bound),1) = eval(b(1:(upper_bound-lower_bound),1));
duration1 = toc()
// case 2 : eval on the complete matrix
tic();
d = zeros((upper_bound-lower_bound),1);
d = string(d);
d = b([1:(upper_bound-lower_bound)],1);
d = eval(d);
duration2 = toc()
// case 3 :with an uggly loop
tic();
e = zeros((upper_bound-lower_bound),1);
for i = 1 : (upper_bound - lower_bound)
e(i,1) = eval(b(i+lower_bound-1,1));
end
duration3 = toc()
// case 4 :with an uggly loop (eval on the complete matrix)
tic();
f = zeros((upper_bound-lower_bound),1);
f = string(f);
for i = 1 : (upper_bound - lower_bound)
f(i,1) = b(i+lower_bound-1,1);
end
f = eval(f);
duration3 = toc()
EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data
_______________________________________________
users mailing list
users at lists.scilab.org<mailto:users at lists.scilab.org>
http://lists.scilab.org/mailman/listinfo/users<https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.scilab.org_mailman_listinfo_users&d=DwMG-g&c=0hKVUfnuoBozYN8UvxPA-w&r=4TCz--8bXfJhZZvIxJAemAJyz7Vfx78XvgYu3LN7eLo&m=lqXcavC4NeUi3iMQNIGQmPIeyYDToYymAQN6OVKhmdY&s=ucgWvT1-1CKXk_NCyJrgfIFxEQ2fKSqX6I1yKKkMZDE&e=>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170630/8de27823/attachment.htm>
More information about the users
mailing list