From 80c74cbf11cdc1a7717303fa5dd561d8fc1c1120 Mon Sep 17 00:00:00 2001 From: ntrifunovic Date: Fri, 11 Aug 2006 22:44:36 +0000 Subject: [PATCH] added utf16>utf8 conversions to performance tests git-svn-id: http://svn.code.sf.net/p/utfcpp/code@41 a809a056-fc17-0410-9590-b4f493f8b08e --- test_drivers/performance/iconvtest.cpp | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test_drivers/performance/iconvtest.cpp b/test_drivers/performance/iconvtest.cpp index 70a9d38..1b9db69 100644 --- a/test_drivers/performance/iconvtest.cpp +++ b/test_drivers/performance/iconvtest.cpp @@ -33,6 +33,7 @@ int main(int argc, char** argv) // fill the data fs8.read(buf, length); + cout << "UTF8 to UTF-16\n"; { memset (utf16buf, 0 , length * sizeof(unsigned short)); // utf-8 cpp: @@ -76,8 +77,43 @@ int main(int argc, char** argv) if (!equal(utf16buf, utf16buf + length, utf16iconvbuf)) cout << "Different result!!!"; + // the other way around + cout << "UTF16 to UTF-8\n"; + { + //iconv + memset(buf, 0, length); + cout<< "iconv: "; + iconv_t cd = iconv_open("UTF-8", "UTF-16LE"); + if (cd == iconv_t(-1)) { + cout << "Error openning the iconv stream"; + return 0; + } + char* inbuf = (char*)utf16buf; + size_t in_bytes_left = length * sizeof(unsigned char); + char* outbuf =buf; + size_t out_bytes_left = length; + { + timer t(cout); + iconv(cd, &inbuf, &in_bytes_left, &outbuf, &out_bytes_left); + } + iconv_close(cd); + } + + { + memset (buf, 0 , length); + // utf-8 cpp: + cout << "unchecked::utf16to8: "; + timer t(cout); + utf8::unchecked::utf16to8(utf16buf, utf16buf + length, buf); + } + { + memset (buf, 0 , length); + cout << "utf16to8: "; + timer t(cout); + utf8::utf16to8(utf16buf, utf16buf + length, buf); + } delete [] buf; delete [] utf16buf; }