Skip to content

Instantly share code, notes, and snippets.

@odeblic
Created July 29, 2017 00:39
Show Gist options
  • Select an option

  • Save odeblic/eab4232e64c062498113ce1bf4a9bb68 to your computer and use it in GitHub Desktop.

Select an option

Save odeblic/eab4232e64c062498113ce1bf4a9bb68 to your computer and use it in GitHub Desktop.
containers
#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