3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 18:31:49 +00:00
z3/lib/timeit.cpp
Leonardo de Moura e9eab22e5c Z3 sources
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-10-02 11:35:25 -07:00

59 lines
1.3 KiB
C++

/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
timeit.h
Abstract:
Support for timers.
Author:
Nikolaj Bjorner (nbjorner) 2006-09-22
Revision History:
--*/
#include<iostream>
#include"timeit.h"
#include"memory_manager.h"
#include"stopwatch.h"
#include<iomanip>
struct timeit::imp {
stopwatch m_watch;
char const * m_msg;
std::ostream & m_out;
double m_start_memory;
imp(char const * msg, std::ostream & out):
m_msg(msg),
m_out(out),
m_start_memory(static_cast<double>(memory::get_allocation_size())/static_cast<double>(1024*1024)) {
m_watch.start();
}
~imp() {
m_watch.stop();
double end_memory = static_cast<double>(memory::get_allocation_size())/static_cast<double>(1024*1024);
m_out << m_msg << ", time: " << std::fixed << std::setprecision(2) << m_watch.get_seconds()
<< " secs, memory: (before " << std::fixed << std::setprecision(2) << m_start_memory
<< ", after " << std::fixed << std::setprecision(2) << end_memory << ")"
<< std::endl;
}
};
timeit::timeit(bool enable, char const * msg, std::ostream & out) {
if (enable)
m_imp = alloc(imp, msg, out);
else
m_imp = 0;
}
timeit::~timeit() {
if (m_imp)
dealloc(m_imp);
}