-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c6fb59
commit 31fab44
Showing
11 changed files
with
253 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: UTimeCounter.h | ||
@Time: 2023/12/3 17:49 | ||
@Desc: | ||
***************************/ | ||
|
||
#ifndef CGRAPH_UTIMECOUNTER_H | ||
#define CGRAPH_UTIMECOUNTER_H | ||
|
||
#include <chrono> | ||
|
||
#include "../UtilsObject.h" | ||
|
||
CGRAPH_NAMESPACE_BEGIN | ||
|
||
class UTimeCounter : public UtilsObject { | ||
public: | ||
explicit UTimeCounter() { | ||
start_ts_ = std::chrono::steady_clock::now(); | ||
} | ||
|
||
~UTimeCounter() override { | ||
std::chrono::duration<double, std::milli> span = std::chrono::steady_clock::now() - start_ts_; | ||
CGraph::CGRAPH_ECHO("time counter is : [%0.2lf] ms", span.count()); | ||
} | ||
|
||
private: | ||
std::chrono::steady_clock::time_point start_ts_; | ||
}; | ||
|
||
CGRAPH_NAMESPACE_END | ||
|
||
#endif //CGRAPH_UTIMECOUNTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: UTimerInclude.h | ||
@Time: 2023/12/3 17:50 | ||
@Desc: | ||
***************************/ | ||
|
||
#ifndef CGRAPH_UTIMERINCLUDE_H | ||
#define CGRAPH_UTIMERINCLUDE_H | ||
|
||
#include "UTimer.h" | ||
#include "UTimeCounter.h" | ||
|
||
#endif //CGRAPH_UTIMERINCLUDE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: TestGNodes.h | ||
@Time: 2023/12/3 17:40 | ||
@Desc: | ||
***************************/ | ||
|
||
#ifndef CGRAPH_TESTGNODES_H | ||
#define CGRAPH_TESTGNODES_H | ||
|
||
#include <atomic> | ||
|
||
#include "CGraph.h" | ||
|
||
std::atomic<unsigned int> g_test_cnt = {0}; | ||
class TestMaterialAdd1GNode : public CGraph::GNode { | ||
public: | ||
CStatus run() override { | ||
g_test_cnt++; | ||
return CStatus(); | ||
} | ||
}; | ||
|
||
#endif //CGRAPH_TESTGNODES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
set(CGRAPH_FUNCTIONAL_LIST | ||
) | ||
|
||
foreach(func ${CGRAPH_FUNCTIONAL_LIST}) | ||
add_executable(${func} | ||
$<TARGET_OBJECTS:CGraph> | ||
${func}.cpp | ||
) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
set(CGRAPH_PERFORMANCE_LIST | ||
test-performance-01 | ||
test-performance-02 | ||
test-performance-03 | ||
) | ||
|
||
|
||
foreach(perf ${CGRAPH_PERFORMANCE_LIST}) | ||
add_executable(${perf} | ||
# 在自己的工程中引入CGraph功能,仅需引入 CGraph-env-include.cmake 后,加入这一句话即可 | ||
$<TARGET_OBJECTS:CGraph> | ||
${perf}.cpp | ||
) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: test-performance-01.cpp | ||
@Time: 2023/12/3 17:41 | ||
@Desc: | ||
***************************/ | ||
|
||
#include "../_materials/TestGNodes.h" | ||
|
||
using namespace CGraph; | ||
|
||
void test_performance_01() { | ||
// 并行的执行32次,对应第1个例子,8thread,32并发,50w次 | ||
GPipelinePtr pipeline = GPipelineFactory::create(); | ||
CStatus status; | ||
GElementPtr arr[32]; | ||
UThreadPoolConfig config; | ||
config.default_thread_size_ = 8; | ||
config.secondary_thread_size_ = 0; | ||
config.max_task_steal_range_ = 7; | ||
config.max_thread_size_ = 8; | ||
config.primary_thread_policy_ = CGRAPH_THREAD_SCHED_RR; | ||
config.primary_thread_priority_ = 10; | ||
config.primary_thread_empty_interval_ = 1; | ||
config.primary_thread_busy_epoch_ = 500; | ||
config.monitor_enable_ = false; // 关闭扩缩容机制 | ||
pipeline->setUniqueThreadPoolConfig(config); | ||
for (auto& i : arr) { | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&i); | ||
} | ||
pipeline->setAutoCheck(false); | ||
status += pipeline->init(); | ||
|
||
{ | ||
UTimeCounter counter; | ||
for (int t = 0; t < 500000; t++) { | ||
pipeline->run(); | ||
} | ||
} | ||
|
||
status += pipeline->destroy(); | ||
GPipelineFactory::remove(pipeline); | ||
} | ||
|
||
|
||
int main() { | ||
test_performance_01(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: test-performance-02.cpp | ||
@Time: 2023/12/3 18:28 | ||
@Desc: | ||
***************************/ | ||
|
||
#include "../_materials/TestGNodes.h" | ||
|
||
using namespace CGraph; | ||
|
||
void test_performance_02() { | ||
// 串行执行32次,对应第二个例子,1thread,32串行,1000w次 | ||
GPipelinePtr pipeline = GPipelineFactory::create(); | ||
CStatus status; | ||
GElementPtr arr[32]; | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&arr[0]); | ||
for (int i = 1; i < 32; i++) { | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&arr[i], {arr[i - 1]}); | ||
} | ||
pipeline->makeSerial(); | ||
pipeline->setAutoCheck(false); | ||
status += pipeline->init(); | ||
{ | ||
UTimeCounter counter; | ||
for (int t = 0; t < 1000000; t++) { | ||
pipeline->run(); | ||
} | ||
} | ||
|
||
status += pipeline->destroy(); | ||
GPipelineFactory::remove(pipeline); | ||
} | ||
|
||
int main() { | ||
test_performance_02(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: test-performance-03.cpp | ||
@Time: 2023/12/3 18:29 | ||
@Desc: | ||
***************************/ | ||
|
||
#include "../_materials/TestGNodes.h" | ||
|
||
using namespace CGraph; | ||
|
||
void test_performance_03() { | ||
// 简单dag场景,对应第三个例子,2thread,dag,100w次 | ||
GPipelinePtr pipeline = GPipelineFactory::create(); | ||
CStatus status; | ||
GElementPtr a,b1,b2,c1,c2,d = nullptr; | ||
UThreadPoolConfig config; | ||
config.default_thread_size_ = 2; // 我的笔记本,是8核心的 macbook pro m1 | ||
config.secondary_thread_size_ = 0; | ||
config.max_task_steal_range_ = 1; | ||
config.max_thread_size_ = 2; | ||
config.primary_thread_empty_interval_ = 1; | ||
config.primary_thread_busy_epoch_ = 500; | ||
config.monitor_enable_ = false; // 关闭扩缩容机制 | ||
config.primary_thread_policy_ = CGRAPH_THREAD_SCHED_RR; | ||
config.primary_thread_priority_ = 10; | ||
pipeline->setUniqueThreadPoolConfig(config); | ||
pipeline->setAutoCheck(false); | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&a); | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&b1, {a}); | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&b2, {b1}); | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&c1, {a}); | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&c2, {c1}); | ||
pipeline->registerGElement<TestMaterialAdd1GNode>(&d, {b2, c2}); | ||
status += pipeline->init(); | ||
|
||
{ | ||
UTimeCounter counter; | ||
for (int t = 0; t < 1000000; t++) { | ||
pipeline->run(); | ||
} | ||
} | ||
|
||
status += pipeline->destroy(); | ||
GPipelineFactory::remove(pipeline); | ||
} | ||
|
||
int main() { | ||
test_performance_03(); | ||
return 0; | ||
} |