changeset 4:8df0d3128672

add time measurement function
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Mon, 04 Feb 2013 03:43:17 +0900
parents f3cfea46e585
children 3602b23914ad
files fft_fixstart/main.cc
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/fft_fixstart/main.cc	Mon Feb 04 02:59:58 2013 +0900
+++ b/fft_fixstart/main.cc	Mon Feb 04 03:43:17 2013 +0900
@@ -3,6 +3,7 @@
 #include <math.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <sys/time.h>
 
 #ifdef __APPLE__
 #include <OpenCL/opencl.h>
@@ -18,6 +19,9 @@
 
 #define AMP(a, b) (sqrt((a)*(a)+(b)*(b)))
 
+static double st_time;
+static double ed_time;
+
 cl_device_id device_id = NULL;
 cl_context context = NULL;
 cl_command_queue queue = NULL;
@@ -29,6 +33,14 @@
     inverse = 1
 };
 
+static double
+getTime()
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return tv.tv_sec + (double)tv.tv_usec*1e-6;
+}
+
 int setWorkSize(size_t* gws, size_t* lws, cl_int x, cl_int y)
 {
     switch(y) {
@@ -210,6 +222,7 @@
         }
     }
 
+    st_time = getTime();
     /* Get platform/device  */
     ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
     ret = clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, &ret_num_devices);
@@ -313,6 +326,7 @@
     /* Finalizations*/
     ret = clFlush(queue);
     ret = clFinish(queue);
+    ed_time = getTime();
     ret = clReleaseKernel(hpfl);
     ret = clReleaseKernel(trns);
     ret = clReleaseKernel(sfac);
@@ -330,6 +344,7 @@
     free(rm);
     free(xm);
 
-    fprintf(stdout, "image out put succeeded.\n");    
+    fprintf(stdout, "image out put succeeded.\n");
+    printf("Time: %0.6f\n",ed_time-st_time);
     return 0;
 }