Created
July 29, 2017 00:39
-
-
Save odeblic/eab4232e64c062498113ce1bf4a9bb68 to your computer and use it in GitHub Desktop.
containers
This file contains hidden or 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
| #include <iostream> | |
| #include <list> | |
| #include <chrono> | |
| #include <functional> | |
| MEASURE(ID, STATEMENT) | |
| M_START(ID) | |
| M_STOP(ID) | |
| class Queue | |
| { | |
| char * allocate(std::size_t size) | |
| { | |
| } | |
| void commit(char * buffer) | |
| { | |
| } | |
| void fetch(std::size_t& size) | |
| { | |
| } | |
| void acknowledge() | |
| { | |
| } | |
| }; | |
| class Intrusive | |
| { | |
| public: | |
| Intrusive noexcept | |
| : previous(nullptr), next(nullptr) | |
| { | |
| }; | |
| ~Intrusive noexcept | |
| { | |
| unlink(); | |
| }; | |
| void link(Intrusive& other) noexcept | |
| { | |
| other.next | |
| } | |
| void unlink() noexcept | |
| { | |
| other.previous | |
| other.next | |
| } | |
| private: | |
| Intrusive * previous; | |
| Intrusive * next; | |
| }; | |
| using node = int; | |
| using duration = std::chrono::nanoseconds; | |
| class Benchmark | |
| { | |
| public: | |
| class Chronometer | |
| { | |
| }; | |
| }; | |
| class Measure | |
| { | |
| public: | |
| using Callback = std::function<void(duration)>; | |
| explicit Measure(Callback callback) | |
| : callback(callback), start(std::chrono::system_clock::now()) | |
| { | |
| } | |
| ~Measure() | |
| { | |
| auto end = std::chrono::system_clock::now(); | |
| auto elapsed = end - start; | |
| callback(std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed)); | |
| } | |
| private: | |
| Callback callback; | |
| std::chrono::system_clock::time_point start; | |
| }; | |
| void xxx() | |
| { | |
| std::list<node> container; | |
| container.push_back(node); | |
| std::string label("id"); | |
| auto callback = [label](duration elapsed) | |
| { | |
| std::cout << elapsed.count() << std::endl; | |
| std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count() << std::endl; | |
| std::cout << std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count() << std::endl; | |
| std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count() << std::endl; | |
| }; | |
| Measure x{callback}; | |
| for(int i=1;i<=2;i++) | |
| std::cout << "zozo" << std::endl; | |
| } | |
| int main(int argc, char * argv[]) | |
| { | |
| std::cout << "Hello World !" << std::endl; | |
| xxx(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment