Λέσχη Φίλων Στατιστικής - GrStats forum
R vs Python execution time comparisons Forumgrstats

Join the forum, it's quick and easy

Λέσχη Φίλων Στατιστικής - GrStats forum
R vs Python execution time comparisons Forumgrstats
Λέσχη Φίλων Στατιστικής - GrStats forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Για προβλήματα εγγραφής και άλλες πληροφορίες επικοινωνήστε με : grstats.forum@gmail.com ή grstats@stat-athens.aueb.gr

Go down
paterask
paterask
Posts : 362
Join date : 2009-10-17
Location : Utrecht, The Netherlands
https://kpatera.github.io/

R vs Python execution time comparisons Empty R vs Python execution time comparisons

Sun 13 Dec 2009 - 3:02
Src: http://www.vpihur.com/blog/?p=151
Running R could be slow at times and implementing computationally intensive parts in C/C++ is recommended. Writing and debugging C code, however, is time consuming and much less convenient than programming in a scripting language like R or Python. To see how execution times of some simple R code compare to Python implementations, we carry out the following simulations:

* Example 1:

# R code
k <- 0
for(i in 1:10^7)
k <- k+i


# Python code
k = 0
for i in range(10**7):
k = k+i


R execution time (in sec): 15.266
Python execution time (in sec): 4.563




* Example 2:

# R code
for(i in 1:10^5)
for(j in 1:1000)
x <- 1


# Python code
for i in range(10**5):
for j in range(1, 1001):
k = 1


R execution time (in sec): 49.609
Python execution time (in sec): 17.65


* Example 3:

# R code
x <- 1:10^7
for(i in 1:10^7)
k <- x[i]


# Python code
x = range(10**7)
for i in range(10**7):
k = x[i]


R execution time (in sec): 13.563
Python execution time (in sec): 3.563
In the three examples here, Python appears to be about 3 times faster than R. Of course, all three examples involve a for loop which is not the best coding practice in R, but there are situations where a loop is necessary (bootstrapping, MCMC, etc). For statistical purposes, R still is a much better choice between the two, but Python is a better programming language overall with numerous libraries for systems programming, game programming, multimedia support and web services.


Last edited by paterask on Tue 5 Apr 2011 - 22:18; edited 2 times in total
grstats
grstats
Posts : 857
Join date : 2009-10-21
http://stat-athens.aueb.gr/~grstats/

R vs Python execution time comparisons Empty Re: R vs Python execution time comparisons

Sun 13 Dec 2009 - 10:59
euxaristw kwsta. auto einai polu xrhsimo. mporeis na deis kai gia th routina ths R pou anebazei ta panta sthn karta grafikwn? an den exeis to site na sto steilw...
paterask
paterask
Posts : 362
Join date : 2009-10-17
Location : Utrecht, The Netherlands
https://kpatera.github.io/

R vs Python execution time comparisons Empty Re: R vs Python execution time comparisons

Sun 13 Dec 2009 - 14:09
Για δώστε πηγή για το τούτο το μαραφέτι της R. Θα βρω ευκαιρία να του ρίξω ματιά σήμερα το βράδυ..
Για διπλά For λογικά θα πηγαίνει πολλαπλασιαστικά η διαφορά του χρόνου μεταξύ R - Python.


Last edited by paterask on Sun 13 Dec 2009 - 14:47; edited 1 time in total
mp83
mp83
Posts : 67
Join date : 2009-11-10
Location : Athens
http://statsravingmad.com/blog

R vs Python execution time comparisons Empty ATLAS Project

Sun 13 Dec 2009 - 14:41
Για Winders (σαν εμένα για λίγο ακόμη) το επόμενο θα δουλεψει καλά (σχεδον το υποσχομαι!) για πράξεις με πίνακες.

R speed increase

For those of you who would like to increase computational speed when using R for matrix calculations, consider the following:

For Windows users, R gets shipped with a pre-compiled Rblass.dll which is not optimized for any specific CPU. However, there exist several CPU-specific Rblass.dlls. Try using those!
You can find some here. For my Core2Duo, I had to look here.
Notice that using the right dll could lead to drastically increased computations.

Example (on my Intel Core2Duo 6600@2.4Ghz, 2GB):

Default….

require(Matrix)
set.seed(123)
X <- Matrix(rnorm(1e6), 1000)
> print(system.time(for(i in 1:25) X%*%X))
user system elapsed
43.20 0.18 43.59
> print(system.time(for(i in 1:25) solve(X)))
user system elapsed
24.87 0.03 25.28
> print(system.time(for(i in 1:10) svd(X)))
user system elapsed
69.47 0.61 70.64

New….

require(Matrix)
set.seed(123)
X <- Matrix(rnorm(1e6), 1000)
> print(system.time(for(i in 1:25) X%*%X))
user system elapsed
7.37 0.12 7.59
> print(system.time(for(i in 1:25) solve(X)))
user system elapsed
7.04 0.18 7.39
> print(system.time(for(i in 1:10) svd(X)))
user system elapsed
43.24 0.69 44.14

Wow!

Because my laptop is a Mac (yes, I am the happy owner of a Macbook Air), I might have a look at this site.
Τα αρχεια βρισκονται εδώ.
This directory contains versions of Rblas.dll linked against the ATLAS library:

- Athlon64_SSE3
- AthlonXP
- PII, PIII, P4, and PM (Pentium M) for various Pentiums
- C2D for Core2Duo (but not necessarily corresponding QuadCore Xeons)


The Rblas.dll in PII, PIII and AthlonXP are linked against ATLAS 3.4.1,
P4 and PM against ATLAS 3.6.0,
Athlon64_SSE3_512k against ATLAS 3.7.37, and
C2D against ATLAS 3.9.11.

Rename ...\bin\Rblas.dll and drop the new Rblas.dll into the ...\bin folder.

Using the wrong version will either not work at all or work much slower
than is possible.
Note that using a different BLAS may also result in numerical issues.
grstats
grstats
Posts : 857
Join date : 2009-10-21
http://stat-athens.aueb.gr/~grstats/

R vs Python execution time comparisons Empty Re: R vs Python execution time comparisons

Tue 15 Dec 2009 - 10:10
euxaristw mp83. an doulepsei tha me swsei. tha sas enhmerwsw an douleuei opote brw xrono kai to dokimasw.

h allh bibliothiki pou upotithetai epitagxunei to R einai h akolouthei http://brainarray.mbni.med.umich.edu/brainarray/rgpgpu/ (xrhsimopoiei thn karta grafikwn).

an to dokimasete dwste feedback.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum