update emoji autocorrect entries from po-files
[LibreOffice.git] / sal / workben / measure_oustrings.cxx
blob0a4eb45b09f20e7a14750b14b663b23056e6a425
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/main.h>
11 #include <rtl/ustring.hxx>
12 #include <osl/time.h>
13 #include <osl/process.h>
15 #include <iostream>
16 #include <sstream>
17 #include <fstream>
19 #if defined HAVE_VALGRIND_HEADERS
20 # include <valgrind/callgrind.h>
21 int COUNT = 1;
22 #else
23 # define CALLGRIND_DUMP_STATS_AT
24 # define CALLGRIND_START_INSTRUMENTATION
25 # define CALLGRIND_STOP_INSTRUMENTATION
26 # define CALLGRIND_ZERO_STATS
27 int COUNT = 10000000;
28 #endif
30 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
31 # define HAVE_CXX_Ox 1
32 #endif
34 #ifdef HAVE_CXX_Ox
35 # define SAL_DECLARE_UTF16(str) u ## str
36 #elif __SIZEOF_WCHAR_T__ == 2
37 # define SAL_DECLARE_UTF16(str) L ## str
38 #endif
40 #ifdef SAL_DECLARE_UTF16
41 # define RTL_CONSTASCII_USTRINGPARAM_WIDE(str) \
42 reinterpret_cast<const sal_Unicode*>(SAL_DECLARE_UTF16(str)), (SAL_N_ELEMENTS(str)-1)
43 #endif
45 #define RTL_CONSTASCII_USTRINGPARAM_CLASSIC(str) \
46 str, ((sal_Int32)(SAL_N_ELEMENTS(str)-1)), RTL_TEXTENCODING_ASCII_US
48 int currenttest = 1;
49 oslProcessInfo pidinfo;
51 class TimerMeasure
53 private:
54 const char *m_pMessage;
55 sal_uInt32 m_nStartTime, m_nEndTime;
56 public:
57 TimerMeasure(const char *pMessage)
58 : m_pMessage(pMessage)
60 m_nStartTime = osl_getGlobalTimer();
61 CALLGRIND_START_INSTRUMENTATION
62 CALLGRIND_ZERO_STATS
65 ~TimerMeasure()
67 CALLGRIND_STOP_INSTRUMENTATION
68 CALLGRIND_DUMP_STATS_AT(m_pMessage);
69 m_nEndTime = osl_getGlobalTimer();
70 std::cout << m_pMessage << std::endl;
71 std::cout << " callgrind Instruction cost is: " << std::flush;
73 std::stringstream aFileName;
74 aFileName << "callgrind.out." << pidinfo.Ident << "." << currenttest;
76 std::ifstream myfile(aFileName.str(), std::ios::in);
77 if (myfile.is_open())
79 std::stringstream aGetGrindStats;
80 aGetGrindStats << "callgrind_annotate " << aFileName.str() <<
81 " | grep TOTALS | sed 's/ PROGRAM TOTALS//'";
82 system(aGetGrindStats.str().c_str());
83 myfile.close();
85 else
86 std::cout << "Unavailable" << std::endl;
87 currenttest++;
88 #ifndef HAVE_CALLGRIND
89 std::cout << " Elapsed tools::Time is: " << m_nEndTime - m_nStartTime << "ms" << std::endl;
90 #endif
94 #define TIME(msg, test) \
96 { test } /*Run the test one to shake out any firsttime lazy loading stuff*/ \
97 TimerMeasure aMeasure(msg);\
98 for (int i = 0; i < COUNT; ++i)\
99 test\
102 SAL_IMPLEMENT_MAIN()
104 CALLGRIND_STOP_INSTRUMENTATION
105 CALLGRIND_ZERO_STATS
107 pidinfo.Size = sizeof(pidinfo);
108 osl_getProcessInfo(0, osl_Process_IDENTIFIER, &pidinfo);
110 #ifdef HAVE_CALLGRIND
111 std::cout << "Execute using: valgrind --tool=callgrind ./measure_oustrings" << std::endl;
112 #else
113 //get my cpu fan up to speed :-)
114 for (int i = 0; i < 10000000; ++i)
116 rtl::OUString sFoo(rtl::OUString::createFromAscii("X"));
117 rtl::OUString sBar(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("X"));
118 rtl::OUString sBaz(static_cast<sal_Unicode>('X'));
119 rtl::OUString sNone;
121 #endif
123 std::cout << "--Empty Strings Construction--" << std::endl;
125 TIME
127 "rtl::OUString()",
128 rtl::OUString sFoo;
131 TIME
133 "rtl::OUString::createFromAscii()",
134 rtl::OUString sFoo(rtl::OUString::createFromAscii(""));
137 std::cout << "--Single Chars Construction--" << std::endl;
139 TIME
141 "rtl::OUString(static_cast<sal_Unicode>('X')",
142 rtl::OUString sBaz(static_cast<sal_Unicode>('X'));
145 #ifdef SAL_DECLARE_UTF16
146 TIME
148 "rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_WIDE(\"X\"))",
149 rtl::OUString sBar(RTL_CONSTASCII_USTRINGPARAM_WIDE("X"));
151 #endif
153 TIME
155 "rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_CLASSIC(\"X\"))",
156 rtl::OUString sBar(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("X"));
159 TIME
161 "rtl::OUString::createFromAscii(\"X\")",
162 rtl::OUString sFoo(rtl::OUString::createFromAscii("X"));
165 std::cout << "--MultiChar Strings Construction--" << std::endl;
167 #ifdef SAL_DECLARE_UTF16
168 TIME
170 "rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_WIDE(\"XXXXXXXX\"))",
171 rtl::OUString sBar(RTL_CONSTASCII_USTRINGPARAM_WIDE("XXXXXXXXXXXXXXX"));
173 #endif
175 TIME
177 "rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_CLASSIC(\"XXXXXXXX\"))",
178 rtl::OUString sBar(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("XXXXXXXXXXXXXXX"));
181 TIME
183 "rtl::OUString::createFromAscii(\"XXXXXXXX\")",
184 rtl::OUString sFoo(rtl::OUString::createFromAscii("XXXXXXXXXXXXXXX"));
187 std::cout << "--Ascii Unequal Comparison--" << std::endl;
189 rtl::OUString sCompare(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("XXXXXXXXXXXXXXX"));
191 TIME
193 "rtl::OUString::equalsAsciiL",
194 sCompare.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("apple"));
197 rtl::OUString sUnequalCompareTo(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("apple"));
199 TIME
201 "operator==(precreated OUString(\"apple\"))",
202 sCompare == sUnequalCompareTo;
205 TIME
207 "rtl::OUString::equalsAscii",
208 sCompare.equalsAscii("apple");
211 //(const sal_Char*, sal_Int32) version has different semantics
212 TIME
214 "rtl::OUString::compareToAscii (const sal_Char*)",
215 sCompare.compareToAscii("apple");
218 TIME
220 "operator==(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_CLASSIC(\"apple\")))",
221 sCompare == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("apple"));
224 std::cout << "--Ascii Equal Comparison--" << std::endl;
226 TIME
228 "rtl::OUString::equalsAsciiL",
229 sCompare.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("XXXXXXXXXXXXXXX"));
232 rtl::OUString sEqualCompareTo(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("XXXXXXXXXXXXXXX"));
234 TIME
236 "operator==(precreated OUString(\"XXXXXXXXXXXXXXX\"))",
237 sCompare == sEqualCompareTo;
240 TIME
242 "rtl::OUString::equalsAscii",
243 sCompare.equalsAscii("XXXXXXXXXXXXXXX");
246 //(const sal_Char*, sal_Int32) version has different semantics
247 TIME
249 "rtl::OUString::compareToAscii (const sal_Char*)",
250 sCompare.compareToAscii("XXXXXXXXXXXXXXX");
253 TIME
255 "operator==(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_CLASSIC(\"XXXXXXXXXXXXXXX\"))",
256 sCompare == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM_CLASSIC("XXXXXXXXXXXXXXX"));
259 return 0;
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */