[Rcpp-commits] r1666 - pkg/Rcpp/inst/examples/SugarPerformance

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 23 14:01:51 CEST 2010


Author: romain
Date: 2010-06-23 14:01:51 +0200 (Wed, 23 Jun 2010)
New Revision: 1666

Modified:
   pkg/Rcpp/inst/examples/SugarPerformance/vectorOps.R
Log:
using Timer

Modified: pkg/Rcpp/inst/examples/SugarPerformance/vectorOps.R
===================================================================
--- pkg/Rcpp/inst/examples/SugarPerformance/vectorOps.R	2010-06-23 11:59:51 UTC (rev 1665)
+++ pkg/Rcpp/inst/examples/SugarPerformance/vectorOps.R	2010-06-23 12:01:51 UTC (rev 1666)
@@ -8,12 +8,10 @@
     unsigned int runs = as<int>(runss);
     int n = x.size() ;
 
-    // Timer timer;
-    // 
-    // // approach one
-    // timer.Start();
-    Function sys_time( "Sys.time") ;
-    double start = as<double>( sys_time( ) );
+    Timer timer;
+    
+    // approach one
+    timer.Start();
     for (unsigned int i=0; i<runs; i++) {
    NumericVector res1( n ) ;
         double x_ = 0.0 ;
@@ -30,34 +28,28 @@
             }
         }
     }
-    // timer.Stop();
-    // double t1 = timer.ElapsedTime();
-    // timer.Reset();
-    double t1 = as<double>( sys_time( ) ) - start;
-
+    timer.Stop();
+    double t1 = timer.ElapsedTime();
+    
     // approach two
-    // timer.Start();   
+    timer.Reset(); timer.Start();   
     start = as<double>( sys_time( ) ) ;
     for (unsigned int i=0; i<runs; i++) {
         NumericVector res2 = ifelse( x < y, x*x, -(y*y) ) ;
     }
-    // timer.Stop();
-    // double t2 = timer.ElapsedTime();
-    double t2 = as<double>( sys_time( ) ) - start;
-
+    timer.Stop();
+    double t2 = timer.ElapsedTime();
     
     ExpressionVector rcode( "ifelse( x<y, x*x, -(y*y) )" ) ;
     Language call = rcode[0] ;
-    start = as<double>( sys_time( ) ) ;
+    
+    timer.Reset(); timer.Start();   
     for (unsigned int i=0; i<runs; i++) {
         NumericVector res2 = Rf_eval( call, R_GlobalEnv ) ;
     }
-    double t3 = as<double>( sys_time( ) ) - start ;
+    timer.Stop();
+    double t3 = timer.ElapsedTime();
     
-    // FIXME return List(Named("standard") = t1,
-    //            Named("sugar")    = t2);
-    // NumericVector v(2); v[0] = t1, v[1] = t2;
-    // return v;
     return NumericVector::create( 
     	_["hand written"] = t1, 
     	_["sugar"] = t2, 



More information about the Rcpp-commits mailing list