Grstats Forum

R vs Python execution time comparisons

Πήγαινε κάτω

R vs Python execution time comparisons

Δημοσίευση από paterask Την / Το Κυρ 13 Δεκ 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.


Έχει επεξεργασθεί από τον/την paterask στις Τρι 5 Απρ 2011 - 22:18, 2 φορές συνολικά
avatar
paterask

Posts : 355
Join date : 17/10/2009
Location : Utrecht, The Netherlands

http://goo.gl/5S6Hpv

Επιστροφή στην κορυφή Πήγαινε κάτω

Απ: R vs Python execution time comparisons

Δημοσίευση από grstats Την / Το Κυρ 13 Δεκ 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...
avatar
grstats

Posts : 700
Join date : 21/10/2009

http://stat-athens.aueb.gr/~grstats/

Επιστροφή στην κορυφή Πήγαινε κάτω

Απ: R vs Python execution time comparisons

Δημοσίευση από paterask Την / Το Κυρ 13 Δεκ 2009 - 14:09

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


Έχει επεξεργασθεί από τον/την paterask στις Κυρ 13 Δεκ 2009 - 14:47, 1 φορά
avatar
paterask

Posts : 355
Join date : 17/10/2009
Location : Utrecht, The Netherlands

http://goo.gl/5S6Hpv

Επιστροφή στην κορυφή Πήγαινε κάτω

ATLAS Project

Δημοσίευση από mp83 Την / Το Κυρ 13 Δεκ 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.
avatar
mp83

Posts : 67
Join date : 10/11/2009
Location : Athens

http://statsravingmad.com/blog

Επιστροφή στην κορυφή Πήγαινε κάτω

Απ: R vs Python execution time comparisons

Δημοσίευση από grstats Την / Το Τρι 15 Δεκ 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.
avatar
grstats

Posts : 700
Join date : 21/10/2009

http://stat-athens.aueb.gr/~grstats/

Επιστροφή στην κορυφή Πήγαινε κάτω

Επιστροφή στην κορυφή

- Παρόμοια θέματα

 
Δικαιώματα σας στην κατηγορία αυτή
Δεν μπορείτε να απαντήσετε στα Θέματα αυτής της Δ.Συζήτησης