사용 중인 BLAS, LAPACK의 성능이 충분한지 판단하기 위해 벤치마크 프로그램을 다운로드해보자. 이 프로그램을 실행하면 여러 가지 선형 대수 연산을 수행하여 R이 이러한 연산을 얼마나 빠르게 수행하는지를 보여준다. 만약 이 성능이 만족스럽지 못하다면 BLAS를 바꿔 속도 향상을 볼 수 있다.

    $ wget http://r.research.att.com/benchmarks/R-benchmark-25.R
    --2014-03-22 18:10:11-- http://r.research.att.com/benchmarks/R-benchmark-25.R
    Resolving r.research.att.com (r.research.att.com)... 207.140.168.126, 2620:0:f00:10::126
    Connecting to r.research.att.com (r.research.att.com)|207.140.168.126|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 13666 (13K) [text/plain]
    Saving to: `R-benchmark-25.R.2'
    
    100%[=============================================>] 13,666      32.7K/s    in 0.4s
    
    2014-03-22 18:10:12 (32.7 KB/s) - `R-benchmark-25.R.2' saved [13666/13666]
    

    이 프로그램을 i7-3740QM 인텔 CPU(코어 4개), 메모리 32G, 우분투 Precise 환경에서 실행한 결과는 다음과 같다.

    $ cat R-benchmark-25.R | time R --slave
    Loading required package: Matrix
    Loading required package: SuppDists
    Warning messages:
    1: In remove("a", "b") : object 'a' not found
    2: In remove("a", "b") : object 'b' not found
    
       R Benchmark 2.5
       ===============
    Number of times each test is run__________________________: 3
    
       I. Matrix calculation 
       ---------------------
    
    Creation, transp., deformation of a 2500x2500 matrix (sec): 0.916333333333333
    2400x2400 normal distributed random matrix ^1000____ (sec): 0.600666666666667
    Sorting of 7,000,000 random values__________________ (sec): 0.662333333333333
    2800x2800 cross-product matrix (b = a' * a)_________ (sec): 1.869
    Linear regr. over a 3000x3000 matrix (c = a \ b')___ (sec): 1.06233333333333
                          --------------------------------------------
                     Trimmed geom. mean (2 extremes eliminated): 0.863900321093131
    
       II. Matrix functions
       --------------------
    FFT over 2,400,000 random values____________________ (sec): 0.387333333333332
    Eigenvalues of a 640x640 random matrix______________ (sec): 0.766000000000001
    Determinant of a 2500x2500 random matrix____________ (sec): 1.30066666666666
    Cholesky decomposition of a 3000x3000 matrix________ (sec): 0.994666666666667
    Inverse of a 1600x1600 random matrix________________ (sec): 1.158
                          --------------------------------------------
                   Trimmed geom. mean (2 extremes eliminated): 0.959117093337175
       III. Programmation
       ------------------
    3,500,000 Fibonacci numbers calculation (vector calc)(sec): 0.653333333333336
    Creation of a 3000x3000 Hilbert matrix (matrix calc) (sec): 0.317666666666665
    Grand common divisors of 400,000 pairs (recursion)__ (sec): 0.903666666666664
    Creation of a 500x500 Toeplitz matrix (loops)_______ (sec): 0.602666666666664
    Escoufier's method on a 45x45 matrix (mixed)________ (sec): 0.434000000000012
                          --------------------------------------------
                    Trimmed geom. mean (2 extremes eliminated): 0.554924508244499
    
    Total time for all 15 tests_________________________ (sec): 12.6286666666667
    Overall mean (sum of I, II and III trimmed means/3)_ (sec): 0.771832492406433
                          --- End of test ---
    

    위 화면에서 보이는 숫자는 각 벤치마크 코드를 실행하는 데 걸린 시간을 의미한다. 실제 숫자는 시스템마다 다르지만 인텔 i7 등의 최신 CPU를 장착한 시스템에서 위 숫자보다 크게 차이나는 값(예를 들어, 위 화면에는 약 1초 정도의 값이 제시되어 있는데 10초가 걸리는 정도의 차이)이 나온다면 BLAS 설정 변경으로 성능을 향상시킬 수도 있다.

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.