You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2016/06/03 07:48:29 UTC

[24/60] incubator-singa git commit: SINGA-165 Add cross-platform timer API to singa Add timer class with cmake compilation. How to test: (in singa main folder) mkdir build && cd build cmake .. make ./bin/timer

SINGA-165 Add cross-platform timer API to singa
Add timer class with cmake compilation.
How to test: (in singa main folder)
	mkdir build && cd build
	cmake ..
	make
	./bin/timer


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/193e9df8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/193e9df8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/193e9df8

Branch: refs/heads/dev
Commit: 193e9df80e9a6dd867635b97648fbf347db31640
Parents: dd1e4af
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Fri May 6 14:05:00 2016 +0800
Committer: xiezl <xi...@comp.nus.edu.sg>
Committed: Fri May 6 15:18:28 2016 +0800

----------------------------------------------------------------------
 CMakeLists.txt                     | 12 ++++++++++++
 include/singa/utils/CMakeLists.txt |  1 +
 include/singa/utils/timer.h        | 17 +++++++++++++++++
 test/singa/CMakeLists.txt          |  4 ++++
 test/singa/test_timer.cc           | 16 ++++++++++++++++
 5 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/193e9df8/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..1daebd5
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,12 @@
+PROJECT(timer)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+MESSAGE(STATUS "flags: " ${CMAKE_CXX_FLAGS})
+MESSAGE(STATUS "paths: " ${CMAKE_CXX_INCLUDE_PATH})
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+SET(CMAKE_CXX_INCLUDE_PATH "${CMAKE_CXX_INCLUDE_PATH} /home/zhongle/singav1/singav1/include/")
+MESSAGE(STATUS "flags: " ${CMAKE_CXX_FLAGS})
+MESSAGE(STATUS "paths: " ${CMAKE_CXX_INCLUDE_PATH})
+ADD_SUBDIRECTORY(test/singa/ bin)
+ADD_SUBDIRECTORY(include/singa/utils/ include/singa/utils/)
+AUX_SOURCE_DIRECTORY( . DIR_SRCS )
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include /home/zhongle/singav1/singav1/include/ )

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/193e9df8/include/singa/utils/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/include/singa/utils/CMakeLists.txt b/include/singa/utils/CMakeLists.txt
new file mode 100644
index 0000000..13b791e
--- /dev/null
+++ b/include/singa/utils/CMakeLists.txt
@@ -0,0 +1 @@
+PROJECT(timer)

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/193e9df8/include/singa/utils/timer.h
----------------------------------------------------------------------
diff --git a/include/singa/utils/timer.h b/include/singa/utils/timer.h
new file mode 100644
index 0000000..dcbabc2
--- /dev/null
+++ b/include/singa/utils/timer.h
@@ -0,0 +1,17 @@
+#ifndef SINGA_UTILS_TIMER_H
+#define SINGA_UTILS_TIMER_H
+
+#include <chrono>
+
+namespace singa{
+
+    class Timer{
+     public:
+        double elapsed() const
+        {
+            return std::chrono::duration<double>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
+        }
+    };
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/193e9df8/test/singa/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/test/singa/CMakeLists.txt b/test/singa/CMakeLists.txt
new file mode 100644
index 0000000..c6f7e9c
--- /dev/null
+++ b/test/singa/CMakeLists.txt
@@ -0,0 +1,4 @@
+PROJECT(timer)
+ADD_EXECUTABLE(timer test_timer.cc)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/193e9df8/test/singa/test_timer.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_timer.cc b/test/singa/test_timer.cc
new file mode 100644
index 0000000..c08d08d
--- /dev/null
+++ b/test/singa/test_timer.cc
@@ -0,0 +1,16 @@
+#include "singa/utils/timer.h"
+#include <iostream>
+#include <unistd.h>
+
+int main(){
+    singa::Timer t;
+    double t1 = t.elapsed();
+    std::cout << "t1 = " << t1 << std::endl;
+    sleep(1);
+    double t2 = t.elapsed();
+    std::cout << "t2 = " << t2 << std::endl;
+    std::cout << "delta = " << t2 - t1 << " ms" << std::endl;
+    
+    return 0;
+
+}