Changeset 34798
- Timestamp:
- 08/06/09 16:53:32 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/objective-cplusplus/i3/trunk/src/mil/src/Test11.cpp
r34796 r34798 14 14 namespace Test11 { 15 15 16 intglobal = 0;16 atomic<int> global = 0; 17 17 atomic<int> spin_status; 18 18 … … 37 37 38 38 // bench class 39 struct BenchReceiver : mil::Module<BenchReceiver> { 39 const unsigned int POST_MAX = 50000; 40 41 struct Bencher : mil::Module<Bencher> { 42 static Bencher benchers[20]; 43 int index; 40 44 int begin; 45 int posted; 46 void setIndex(int index_) { 47 posted = 0; 48 index = index_; 49 } 50 void a() { 51 posted++; 52 if (posted == POST_MAX) { 53 AllPosted e; 54 benchers[index].post(e, *this); 55 } 56 } 57 void execute(TinyEvent& e) { 58 global.fetch_and_add(1); 59 benchers[index].post(e, *this); 60 a(); 61 } 62 void execute(SmallEvent& e) { 63 global.fetch_and_add(e.data * 2); 64 benchers[index].post(e, *this); 65 a(); 66 } 67 void execute(MiddleEvent& e) { 68 global.fetch_and_add(e.data * 2); 69 benchers[index].post(e, *this); 70 a(); 71 } 72 void execute(BigEvent& e) { 73 global.fetch_and_add(e.data * 2); 74 benchers[index].post(e, *this); 75 a(); 76 } 77 void execute(AllPosted& e) { 78 printf("AllPosted Received : %lf, global = %d, index = %d\n", 79 (double)(clock() - begin) / CLOCKS_PER_SEC, global.load(), index); 80 spin_status.fetch_and_add(1); 81 } 41 82 void run() { 42 83 while (spin_status.load()) {} 43 84 begin = clock(); 85 for (int i = 0; i < 5; i++) { 86 TinyEvent t; 87 benchers[index].post(t, *this); 88 SmallEvent s; 89 s.data = 8; 90 benchers[index].post(s, *this); 91 //MiddleEvent m; 92 //m.data = 16; 93 //r.post(m, *this); 94 //BigEvent b; 95 //b.data = 32; 96 //r.post(b, *this); 97 } 44 98 this->loop(); 45 }46 void execute(TinyEvent& e) {47 global += 2;48 }49 void execute(SmallEvent& e) {50 global += e.data * 2;51 }52 void execute(MiddleEvent& e) {53 global += e.data * 2;54 }55 void execute(BigEvent& e) {56 global += e.data * 2;57 }58 void execute(AllPosted& e) {59 printf("AllPosted Received : %lf, global = %d\n",60 (double)(clock() - begin) / CLOCKS_PER_SEC, global);61 spin_status.store(2);62 99 } 63 100 }; 64 101 65 struct BenchSender : mil::Module<BenchSender> { 66 int begin; 67 BenchReceiver& r; 68 BenchSender(BenchReceiver& r) : r(r) {} 69 void run() { 70 while (spin_status.load()) {} 71 begin = clock(); 72 for (int i = 0; i < 5000000; i++) { 73 TinyEvent t; 74 r.post(t, *this); 75 SmallEvent s; 76 s.data = 8; 77 r.post(s, *this); 78 MiddleEvent m; 79 m.data = 16; 80 //r.post(m, *this); 81 BigEvent b; 82 b.data = 32; 83 //r.post(b, *this); 84 } 85 AllPosted a; 86 r.post(a, *this); 87 88 while (spin_status.load() != 2) { 89 while (this->execute_front()) { 90 } 91 } 92 printf("run end : %lf, global = %d\n", 93 (double)(clock() - begin) / CLOCKS_PER_SEC, global); 94 spin_status.store(3); 95 } 96 }; 102 Bencher Bencher::benchers[20]; 97 103 98 104 } … … 101 107 102 108 QT_TEST(test_iaodfioasdfadfaadfasdfadfiiiii) { 103 BenchReceiver r;104 BenchSender s(r);105 109 spin_status.store(1); 106 r.start(); 107 s.start(); 108 sleep(1); 110 111 for (size_t i = 0; i < _countof(Bencher::benchers); i++) { 112 Bencher::benchers[i].setIndex((i + 1) % _countof(Bencher::benchers)); 113 Bencher::benchers[i].start(); 114 } 115 109 116 spin_status.store(0); 110 117 111 while (spin_status.load() != 3) {} 112 118 while (spin_status.load() != _countof(Bencher::benchers)) { 119 Sleep(10); 120 } 113 121 } 114 122
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)