[Bf-blender-cvs] [1472b4a77f8] functions: simple to use function timer

Jacques Lucke noreply at git.blender.org
Wed Feb 20 17:21:43 CET 2019


Commit: 1472b4a77f813e78b41f1612ab25b8a55c6e0206
Author: Jacques Lucke
Date:   Wed Feb 20 17:19:09 2019 +0100
Branches: functions
https://developer.blender.org/rB1472b4a77f813e78b41f1612ab25b8a55c6e0206

simple to use function timer

===================================================================

A	source/blender/blenlib/BLI_timeit.hpp
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/functions/c_wrapper.cpp

===================================================================

diff --git a/source/blender/blenlib/BLI_timeit.hpp b/source/blender/blenlib/BLI_timeit.hpp
new file mode 100644
index 00000000000..ff6e761422b
--- /dev/null
+++ b/source/blender/blenlib/BLI_timeit.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <chrono>
+#include <iostream>
+
+namespace BLI {
+
+	class Timer {
+	private:
+		const char *name;
+		std::chrono::high_resolution_clock::time_point start, end;
+		std::chrono::duration<float> duration;
+
+	public:
+		Timer(const char *name = "")
+		{
+			this->name = name;
+			this->start = std::chrono::high_resolution_clock::now();
+		}
+
+		~Timer()
+		{
+			end = std::chrono::high_resolution_clock::now();
+			duration = end - start;
+			double ms = duration.count() * 1000.0f;
+			std::cout << "Timer '" << name << "' took " << ms << " ms" << std::endl;
+		}
+	};
+
+};
+
+#define TIMEIT(name) BLI::Timer t(name);
\ No newline at end of file
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 0e8f87db992..ebe0a00e368 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -235,6 +235,7 @@ set(SRC
 	BLI_small_set.hpp
 	BLI_small_set_vector.hpp
 	BLI_small_stack.hpp
+	BLI_timeit.hpp
 )
 
 if(WITH_MEM_VALGRIND)
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index 0af4a389c81..7121692977d 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -4,7 +4,7 @@
 #include "nodes/nodes.hpp"
 #include "nodes/graph_generation.hpp"
 
-#include "BLI_lazy_init.hpp"
+#include "BLI_timeit.hpp"
 
 #include <iostream>
 
@@ -149,11 +149,11 @@ SIMPLE_TYPE_GETTER(float);
 SIMPLE_TYPE_GETTER(int32);
 SIMPLE_TYPE_GETTER(fvec3);
 
-
 FnFunction FN_tree_to_function(bNodeTree *btree)
 {
+	TIMEIT("Tree to function");
 	auto fgraph = FN::Nodes::btree_to_graph(btree);
-	std::cout << fgraph.graph()->to_dot() << std::endl;
+	//std::cout << fgraph.graph()->to_dot() << std::endl;
 
 	auto fn = FN::SharedFunction::New("Function from Node Tree", fgraph.signature());
 	fn->add_body(FN::function_graph_to_callable(fgraph));



More information about the Bf-blender-cvs mailing list