Fixed the iconvtest performance test
git-svn-id: http://svn.code.sf.net/p/utfcpp/code@42 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
parent
80c74cbf11
commit
2656dc5872
1 changed files with 19 additions and 13 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
using namespace utf8;
|
using namespace utf8;
|
||||||
|
@ -27,15 +28,19 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
// allocate the buffer (no vector - we are benchmarking conversions, not STL
|
// allocate the buffer (no vector - we are benchmarking conversions, not STL
|
||||||
char* buf = new char[length];
|
char* buf = new char[length];
|
||||||
fs8.close();
|
char* end_buf = buf + length;
|
||||||
// the UTF-16 result will not be larger than this (I hope :) )
|
|
||||||
unsigned short* utf16buf = new unsigned short[length];
|
|
||||||
// fill the data
|
// fill the data
|
||||||
fs8.read(buf, length);
|
fs8.read(buf, length);
|
||||||
|
fs8.close();
|
||||||
|
// the UTF-16 result will not be larger than this (I hope :) )
|
||||||
|
vector<unsigned char> temputf16;
|
||||||
|
utf8::utf8to16(buf, end_buf, back_inserter(temputf16));
|
||||||
|
int wlength = temputf16.size();
|
||||||
|
unsigned short* utf16buf = new unsigned short[wlength];
|
||||||
|
|
||||||
cout << "UTF8 to UTF-16\n";
|
cout << "UTF8 to UTF-16\n";
|
||||||
{
|
{
|
||||||
memset (utf16buf, 0 , length * sizeof(unsigned short));
|
memset (utf16buf, 0 , wlength * sizeof(unsigned short));
|
||||||
// utf-8 cpp:
|
// utf-8 cpp:
|
||||||
cout << "utf8::utf8to16: ";
|
cout << "utf8::utf8to16: ";
|
||||||
timer t(cout);
|
timer t(cout);
|
||||||
|
@ -43,7 +48,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
memset (utf16buf, 0 , length * sizeof(unsigned short));
|
memset (utf16buf, 0 , wlength * sizeof(unsigned short));
|
||||||
// utf-8 cpp:
|
// utf-8 cpp:
|
||||||
cout << "unchecked::utf8to16: ";
|
cout << "unchecked::utf8to16: ";
|
||||||
timer t(cout);
|
timer t(cout);
|
||||||
|
@ -51,9 +56,9 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the UTF-16 result will not be larger than this (I hope :) )
|
// the UTF-16 result will not be larger than this (I hope :) )
|
||||||
unsigned short* utf16iconvbuf = new unsigned short[length];
|
unsigned short* utf16iconvbuf = new unsigned short[wlength];
|
||||||
{
|
{
|
||||||
memset (utf16iconvbuf, 0 , length * sizeof(unsigned short));
|
memset (utf16iconvbuf, 0 , wlength * sizeof(unsigned short));
|
||||||
// iconv
|
// iconv
|
||||||
cout << "iconv: ";
|
cout << "iconv: ";
|
||||||
|
|
||||||
|
@ -65,7 +70,7 @@ int main(int argc, char** argv)
|
||||||
char* inbuf = buf;
|
char* inbuf = buf;
|
||||||
size_t in_bytes_left = length;
|
size_t in_bytes_left = length;
|
||||||
char* outbuf = (char*)utf16iconvbuf;
|
char* outbuf = (char*)utf16iconvbuf;
|
||||||
size_t out_bytes_left = length * sizeof (unsigned char);
|
size_t out_bytes_left = wlength * sizeof (unsigned short);
|
||||||
{
|
{
|
||||||
timer t(cout);
|
timer t(cout);
|
||||||
iconv(cd, &inbuf, &in_bytes_left, &outbuf, &out_bytes_left);
|
iconv(cd, &inbuf, &in_bytes_left, &outbuf, &out_bytes_left);
|
||||||
|
@ -74,8 +79,8 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// just check the correctness while we are here:
|
// just check the correctness while we are here:
|
||||||
if (!equal(utf16buf, utf16buf + length, utf16iconvbuf))
|
if (!equal(utf16buf, utf16buf + wlength, utf16iconvbuf))
|
||||||
cout << "Different result!!!";
|
cout << "Different result!!!\n";
|
||||||
|
|
||||||
// the other way around
|
// the other way around
|
||||||
cout << "UTF16 to UTF-8\n";
|
cout << "UTF16 to UTF-8\n";
|
||||||
|
@ -90,7 +95,7 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
char* inbuf = (char*)utf16buf;
|
char* inbuf = (char*)utf16buf;
|
||||||
size_t in_bytes_left = length * sizeof(unsigned char);
|
size_t in_bytes_left = wlength * sizeof(unsigned short);
|
||||||
char* outbuf =buf;
|
char* outbuf =buf;
|
||||||
size_t out_bytes_left = length;
|
size_t out_bytes_left = length;
|
||||||
{
|
{
|
||||||
|
@ -105,15 +110,16 @@ int main(int argc, char** argv)
|
||||||
// utf-8 cpp:
|
// utf-8 cpp:
|
||||||
cout << "unchecked::utf16to8: ";
|
cout << "unchecked::utf16to8: ";
|
||||||
timer t(cout);
|
timer t(cout);
|
||||||
utf8::unchecked::utf16to8(utf16buf, utf16buf + length, buf);
|
utf8::unchecked::utf16to8(utf16buf, utf16buf + wlength, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
memset (buf, 0 , length);
|
memset (buf, 0 , length);
|
||||||
cout << "utf16to8: ";
|
cout << "utf16to8: ";
|
||||||
timer t(cout);
|
timer t(cout);
|
||||||
utf8::utf16to8(utf16buf, utf16buf + length, buf);
|
utf8::utf16to8(utf16buf, utf16buf + wlength, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
delete [] utf16buf;
|
delete [] utf16buf;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue