[prev in list] [next in list] [prev in thread] [next in thread] 

List:       scilab-users
Subject:    Re: [Scilab-users] On computational speed
From:       Federico Miyara <fmiyara () fceia ! unr ! edu ! ar>
Date:       2023-11-30 15:51:48
Message-ID: 12d98323-c8ee-d6e3-1ec6-a5df23a5530d () fceia ! unr ! edu ! ar
[Download RAW message or body]


Heinz,

Thank you for your timings, which confirm that, even if about an order
of magnitude faster (I use a rather old i7 laptop), the simple squaring
operation takes much longer than it should.

Regards,

Federico Miyara

On 30/11/2023 02:14, Heinz Nabielek wrote:
> Thanks. In the 1960s FORTRAN, we would always write A2=A*A rather than A2=A**2.
> 
> Below the Federico examples on my M1 Apple silicon iMac:
> Heinz
> 
> --> tic, u = rand(1,1e7); toc
> ans  =   0.111413
> 
> --> tic, v = sqrt(u); toc
> ans  =   0.0384130
> 
> -->  tic, v = u.*u; toc
> ans  =   0.023148
> 
> --> tic, v = u.*%pi; toc
> ans  =   0.017872
> 
> --> tic, v = u.^2; toc
> ans  =   0.156129
> 
> --> tic, v = u.^%pi; toc
> ans  =   0.1537830
> 
> --> tic, v = log(u); toc
> ans  =   0.093586
> 
> --> tic, v = exp(u); toc
> ans  =   0.0821170
> 
> --> tic, v = exp(2*log(u)); toc
> ans  =   0.139802
> 
> 
> 
> 
> 
> > Am 30.11.2023 um 00:46 schrieb Federico Miyara <fmiyara@fceia.unr.edu.ar>:
> > 
> > Dear All,
> > 
> > I was trying to make some simple experiments regarding computational speed of \
> > several functions and operations and some results puzzled me. To perform the \
> > tests I used massive data to minimize the effect of idle time due to priority \
> > handling by the operating system or whatever. 
> > --> tic, u = rand(1,1e7); toc
> > ans  =
> > 0.4948326
> > 
> > This creates ten million random numbers in half a second. Very decent \
> > performance. Then 
> > --> tic, v = sqrt(u); toc
> > ans  =
> > 0.282802
> > 
> > The algorithm for square root seems quite fast. Multiplication
> > 
> > --> tic, v = u.*u; toc
> > ans  =
> > 0.1218028
> > 
> > --> tic, v = u.*%pi; toc
> > ans  =
> > 0.119245
> > 
> > is really fast. But when it comes to power or exponentiation:
> > 
> > --> tic, v = u.^2; toc
> > ans  =
> > 1.9633435
> > 
> > --> tic, v = u.^%pi; toc
> > ans  =
> > 1.958321
> > 
> > it is quite slow. Logarithm is much faster:
> > 
> > --> tic, v = log(u); toc
> > ans  =
> > 0.5166959
> > 
> > Even the exponential function with base e is much faster:
> > 
> > --> tic, v = exp(u); toc
> > ans  =
> > 0.5451482
> > 
> > I wonder why special cases such as small integer powers are not dealt with by \
> > simple multiplication. Particularly the square is very frequently used on large \
> > vectors representing discrete signals (for instance to get energy measures) and \
> > no warning is issued in the documentation. 
> > I also notice that computing the square using this formula (a cannon to kill a \
> > mosquito!) 
> > --> tic, v = exp(2*log(u)); toc
> > ans  =
> > 1.2789763
> > 
> > is faster than using the power operator ^.
> > 
> > This seems to be an inconsistent approach, since many special functions are \
> > painstakingly tailored to be very efficient, yet one of the simplest of all \
> > operations, raising to power 2, is sluggishly slow... 
> > Regards,
> > 
> > Federico Miyara
> > 
> > 
> > Libre de virus.www.avast.com This email and any attachments are intended solely \
> > for the use of the individual or entity to whom it is addressed and may be \
> > confidential and/or privileged. If you are not one of the named recipients or \
> > have received this email in error, (i) you should not read, disclose, or copy it,
> > (ii) please notify sender of your receipt by reply email and delete this email \
> > and all attachments, (iii) Dassault Systèmes does not accept or assume any \
> > liability or responsibility for any use of or reliance on this email. 
> > Please be informed that your personal data are processed according to our data \
> > privacy policy as described on our website. Should you have any questions related \
> > to personal data protection, please contact 3DS Data Protection Officer \
> > https://www.3ds.com/privacy-policy/contact/ 
> > _______________________________________________
> > users mailing list - users@lists.scilab.org
> > Click here to unsubscribe: <mailto:users-unsubscribe@lists.scilab.org>
> > https://lists.scilab.org/mailman/listinfo/users
> _______________________________________________
> users mailing list - users@lists.scilab.org
> Click here to unsubscribe: <mailto:users-unsubscribe@lists.scilab.org>
> https://lists.scilab.org/mailman/listinfo/users
> This email and any attachments are intended solely for the use of the individual or \
> entity to whom it is addressed and may be confidential and/or privileged. 
> If you are not one of the named recipients or have received this email in error,
> 
> (i) you should not read, disclose, or copy it,
> 
> (ii) please notify sender of your receipt by reply email and delete this email and \
> all attachments, 
> (iii) Dassault Systèmes does not accept or assume any liability or responsibility \
> for any use of or reliance on this email. 
> 
> Please be informed that your personal data are processed according to our data \
> privacy policy as described on our website. Should you have any questions related \
> to personal data protection, please contact 3DS Data Protection Officer \
> https://www.3ds.com/privacy-policy/contact/ 
> 


--
Este correo electrónico ha sido analizado en busca de virus por el software \
antivirus de Avast. www.avast.com
_______________________________________________
users mailing list - users@lists.scilab.org
Click here to unsubscribe: <mailto:users-unsubscribe@lists.scilab.org>
https://lists.scilab.org/mailman/listinfo/users
This email and any attachments are intended solely for the use of the individual or \
entity to whom it is addressed and may be confidential and/or privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email and \
all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or responsibility \
for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data \
privacy policy as described on our website. Should you have any questions related to \
personal data protection, please contact 3DS Data Protection Officer \
https://www.3ds.com/privacy-policy/contact/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic