Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: runtime/vm/benchmark_test.cc

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/benchmark_test.h" 5 #include "vm/benchmark_test.h"
6 6
7 #include "bin/file.h" 7 #include "bin/file.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 10
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 " c.method(i,7);\n" 166 " c.method(i,7);\n"
167 " }\n" 167 " }\n"
168 "}\n"; 168 "}\n";
169 169
170 Dart_Handle lib = TestCase::LoadTestScript( 170 Dart_Handle lib = TestCase::LoadTestScript(
171 kScriptChars, 171 kScriptChars,
172 reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup)); 172 reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup));
173 173
174 // Create a native wrapper class with native fields. 174 // Create a native wrapper class with native fields.
175 Dart_Handle result = Dart_CreateNativeWrapperClass( 175 Dart_Handle result = Dart_CreateNativeWrapperClass(
176 lib, 176 lib, NewString("NativeFieldsWrapper"), 1);
177 Dart_NewString("NativeFieldsWrapper"),
178 1);
179 EXPECT_VALID(result); 177 EXPECT_VALID(result);
180 178
181 Dart_Handle args[1]; 179 Dart_Handle args[1];
182 args[0] = Dart_NewInteger(kNumIterations); 180 args[0] = Dart_NewInteger(kNumIterations);
183 181
184 // Warmup first to avoid compilation jitters. 182 // Warmup first to avoid compilation jitters.
185 Dart_Invoke(lib, 183 Dart_Invoke(lib, NewString("benchmark"), 1, args);
186 Dart_NewString("benchmark"),
187 1,
188 args);
189 184
190 Timer timer(true, "UseDartApi benchmark"); 185 Timer timer(true, "UseDartApi benchmark");
191 timer.Start(); 186 timer.Start();
192 Dart_Invoke(lib, 187 Dart_Invoke(lib, NewString("benchmark"), 1, args);
193 Dart_NewString("benchmark"),
194 1,
195 args);
196 timer.Stop(); 188 timer.Stop();
197 int64_t elapsed_time = timer.TotalElapsedTime(); 189 int64_t elapsed_time = timer.TotalElapsedTime();
198 benchmark->set_score(elapsed_time); 190 benchmark->set_score(elapsed_time);
199 } 191 }
200 192
201 193
202 // 194 //
203 // Measure time accessing internal and external strings. 195 // Measure time accessing internal and external strings.
204 // 196 //
205 BENCHMARK(DartStringAccess) { 197 BENCHMARK(DartStringAccess) {
206 const int kNumIterations = 10000000; 198 const int kNumIterations = 10000000;
207 Timer timer(true, "DartStringAccess benchmark"); 199 Timer timer(true, "DartStringAccess benchmark");
208 timer.Start(); 200 timer.Start();
209 Dart_EnterScope(); 201 Dart_EnterScope();
210 202
211 // Create strings. 203 // Create strings.
212 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; 204 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
213 int external_peer_data = 123; 205 int external_peer_data = 123;
214 Dart_Handle external_string = Dart_NewExternalString8(data8, 206 Dart_Handle external_string = Dart_NewExternalUTF8String(data8,
215 ARRAY_SIZE(data8), 207 ARRAY_SIZE(data8),
216 &external_peer_data, 208 &external_peer_data,
217 NULL); 209 NULL);
218 Dart_Handle internal_string = Dart_NewString("two"); 210 Dart_Handle internal_string = NewString("two");
219 211
220 // Run benchmark. 212 // Run benchmark.
221 for (int64_t i = 0; i < kNumIterations; i++) { 213 for (int64_t i = 0; i < kNumIterations; i++) {
222 EXPECT(Dart_IsString(internal_string)); 214 EXPECT(Dart_IsString(internal_string));
223 EXPECT(Dart_IsString8(internal_string));
224 EXPECT(Dart_IsString16(internal_string));
225 EXPECT(!Dart_IsExternalString(internal_string)); 215 EXPECT(!Dart_IsExternalString(internal_string));
226 EXPECT_VALID(external_string); 216 EXPECT_VALID(external_string);
227 EXPECT(Dart_IsExternalString(external_string)); 217 EXPECT(Dart_IsExternalString(external_string));
228 void* external_peer = NULL; 218 void* external_peer = NULL;
229 EXPECT_VALID(Dart_ExternalStringGetPeer(external_string, &external_peer)); 219 EXPECT_VALID(Dart_ExternalStringGetPeer(external_string, &external_peer));
230 EXPECT_EQ(&external_peer_data, external_peer); 220 EXPECT_EQ(&external_peer_data, external_peer);
231 } 221 }
232 222
233 Dart_ExitScope(); 223 Dart_ExitScope();
234 timer.Stop(); 224 timer.Stop();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 "}" 370 "}"
381 "class StackFrameTest {" 371 "class StackFrameTest {"
382 " static int testMain() {" 372 " static int testMain() {"
383 " First obj = new First();" 373 " First obj = new First();"
384 " return obj.method1(1);" 374 " return obj.method1(1);"
385 " }" 375 " }"
386 "}"; 376 "}";
387 Dart_Handle lib = TestCase::LoadTestScript( 377 Dart_Handle lib = TestCase::LoadTestScript(
388 kScriptChars, 378 kScriptChars,
389 reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver)); 379 reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver));
390 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); 380 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest"));
391 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); 381 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
392 EXPECT_VALID(result); 382 EXPECT_VALID(result);
393 int64_t elapsed_time = 0; 383 int64_t elapsed_time = 0;
394 result = Dart_IntegerToInt64(result, &elapsed_time); 384 result = Dart_IntegerToInt64(result, &elapsed_time);
395 EXPECT_VALID(result); 385 EXPECT_VALID(result);
396 benchmark->set_score(elapsed_time); 386 benchmark->set_score(elapsed_time);
397 } 387 }
398 388
399 } // namespace dart 389 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698