Minor improvements to performance testing code

git-svn-id: http://svn.code.sf.net/p/utfcpp/code@115 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
ntrifunovic 2010-09-04 16:10:35 +00:00 committed by King_DuckZ
parent d75756f201
commit 7fcdf850d9
2 changed files with 11 additions and 4 deletions

View file

@ -3,19 +3,20 @@
struct timer {
timer(std::ostream& report) : report(report)
{start = std::clock();}
~timer()
void print_time()
{
using namespace std;
end = clock();
unsigned milliseconds = (end - start)*1000 / CLOCKS_PER_SEC;
clock_t now = clock();
unsigned milliseconds = (now - start)*1000 / CLOCKS_PER_SEC;
report << "Spent " << milliseconds << "ms here\n";
}
std::clock_t start;
std::clock_t end;
std::ostream& report;
private:
// just to surpress a VC++ 8.0 warning
timer& operator = (const timer&);
timer(const timer&);
};

View file

@ -44,6 +44,7 @@ int main(int argc, char** argv)
cout << "utf8::utf8to16: ";
timer t(cout);
utf8::utf8to16(buf, buf + length, utf16buf);
t.print_time();
}
{
@ -52,6 +53,7 @@ int main(int argc, char** argv)
cout << "unchecked::utf8to16: ";
timer t(cout);
utf8::unchecked::utf8to16(buf, buf + length, utf16buf);
t.print_time();
}
// the UTF-16 result will not be larger than this (I hope :) )
wchar_t* utf16iconvbuf = new wchar_t[wlength];
@ -63,6 +65,7 @@ int main(int argc, char** argv)
{
timer t(cout);
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, buf, length, utf16iconvbuf, int(wlength));
t.print_time();
}
}
@ -81,6 +84,7 @@ int main(int argc, char** argv)
{
timer t(cout);
WideCharToMultiByte(CP_UTF8, 0, utf16buf, int(wlength), buf, length, NULL, NULL);
t.print_time();
}
}
@ -90,6 +94,7 @@ int main(int argc, char** argv)
cout << "unchecked::utf16to8: ";
timer t(cout);
utf8::unchecked::utf16to8(utf16buf, utf16buf + wlength, buf);
t.print_time();
}
{
@ -97,6 +102,7 @@ int main(int argc, char** argv)
cout << "utf16to8: ";
timer t(cout);
utf8::utf16to8(utf16buf, utf16buf + wlength, buf);
t.print_time();
}
delete [] buf;