| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 end = scanner.scanner_->location().end_pos; | 204 end = scanner.scanner_->location().end_pos; |
| 205 if (dump_tokens) { | 205 if (dump_tokens) { |
| 206 tokens->push_back(TokenWithLocation(token, beg, end)); | 206 tokens->push_back(TokenWithLocation(token, beg, end)); |
| 207 } | 207 } |
| 208 } while (token != Token::EOS); | 208 } while (token != Token::EOS); |
| 209 return timer.Elapsed(); | 209 return timer.Elapsed(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 | 212 |
| 213 template<typename YYCTYPE> | 213 template<typename YYCTYPE> |
| 214 TimeDelta RunExperimentalScanner(const char* fname, | 214 TimeDelta RunExperimentalScanner(Handle<String> source, |
| 215 Isolate* isolate, | 215 Isolate* isolate, |
| 216 Encoding encoding, | 216 Encoding encoding, |
| 217 bool dump_tokens, | 217 bool dump_tokens, |
| 218 std::vector<TokenWithLocation>* tokens, | 218 std::vector<TokenWithLocation>* tokens, |
| 219 int repeat, | 219 int repeat, |
| 220 HarmonySettings harmony_settings) { | 220 HarmonySettings harmony_settings) { |
| 221 ElapsedTimer timer; | 221 ElapsedTimer timer; |
| 222 byte* buffer_end = 0; | |
| 223 YYCTYPE* buffer = reinterpret_cast<YYCTYPE*>( | |
| 224 ReadFile(fname, &buffer_end, repeat, encoding == UTF8TO16)); | |
| 225 | |
| 226 timer.Start(); | 222 timer.Start(); |
| 227 ExperimentalScanner<YYCTYPE> scanner( | 223 ExperimentalScanner<YYCTYPE> scanner(source, isolate); |
| 228 buffer, reinterpret_cast<YYCTYPE*>(buffer_end), isolate); | |
| 229 scanner.SetHarmonyNumericLiterals(harmony_settings.numeric_literals); | 224 scanner.SetHarmonyNumericLiterals(harmony_settings.numeric_literals); |
| 230 scanner.SetHarmonyModules(harmony_settings.modules); | 225 scanner.SetHarmonyModules(harmony_settings.modules); |
| 231 scanner.SetHarmonyScoping(harmony_settings.scoping); | 226 scanner.SetHarmonyScoping(harmony_settings.scoping); |
| 232 | 227 |
| 233 Token::Value token; | 228 Token::Value token; |
| 234 int beg, end; | 229 int beg, end; |
| 235 do { | 230 do { |
| 236 token = scanner.Next(); | 231 token = scanner.Next(); |
| 237 beg = scanner.location().beg_pos; | 232 beg = scanner.location().beg_pos; |
| 238 end = scanner.location().end_pos; | 233 end = scanner.location().end_pos; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 266 } |
| 272 HandleScope handle_scope(isolate); | 267 HandleScope handle_scope(isolate); |
| 273 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens; | 268 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens; |
| 274 TimeDelta baseline_time, experimental_time; | 269 TimeDelta baseline_time, experimental_time; |
| 275 if (run_baseline) { | 270 if (run_baseline) { |
| 276 baseline_time = RunBaselineScanner( | 271 baseline_time = RunBaselineScanner( |
| 277 fname, isolate, encoding, print_tokens || check_tokens, | 272 fname, isolate, encoding, print_tokens || check_tokens, |
| 278 &baseline_tokens, repeat, harmony_settings); | 273 &baseline_tokens, repeat, harmony_settings); |
| 279 } | 274 } |
| 280 if (run_experimental) { | 275 if (run_experimental) { |
| 276 Handle<String> source; |
| 277 byte* buffer_end = 0; |
| 278 const byte* buffer = ReadFile(fname, &buffer_end, repeat, |
| 279 encoding == UTF8TO16); |
| 281 switch (encoding) { | 280 switch (encoding) { |
| 282 case UTF8: | 281 case UTF8: |
| 283 experimental_time = RunExperimentalScanner<int8_t>( | |
| 284 fname, isolate, encoding, print_tokens || check_tokens, | |
| 285 &experimental_tokens, repeat, harmony_settings); | |
| 286 break; | |
| 287 case LATIN1: | 282 case LATIN1: |
| 283 source = isolate->factory()->NewStringFromAscii( |
| 284 Vector<const char>(reinterpret_cast<const char*>(buffer), |
| 285 buffer_end - buffer)); |
| 288 experimental_time = RunExperimentalScanner<uint8_t>( | 286 experimental_time = RunExperimentalScanner<uint8_t>( |
| 289 fname, isolate, encoding, print_tokens || check_tokens, | 287 source, isolate, encoding, print_tokens || check_tokens, |
| 290 &experimental_tokens, repeat, harmony_settings); | 288 &experimental_tokens, repeat, harmony_settings); |
| 291 break; | 289 break; |
| 292 case UTF16: | 290 case UTF16: |
| 291 case UTF8TO16: { |
| 292 const uc16* buffer_16 = reinterpret_cast<const uc16*>(buffer); |
| 293 const uc16* buffer_end_16 = reinterpret_cast<const uc16*>(buffer_end); |
| 294 source = isolate->factory()->NewStringFromTwoByte( |
| 295 Vector<const uc16>(buffer_16, buffer_end_16 - buffer_16)); |
| 296 // If the string was just an expaneded one byte string, V8 detects it |
| 297 // and doesn't store it as two byte. |
| 298 CHECK(source->IsTwoByteRepresentation()); |
| 293 experimental_time = RunExperimentalScanner<uint16_t>( | 299 experimental_time = RunExperimentalScanner<uint16_t>( |
| 294 fname, isolate, encoding, print_tokens || check_tokens, | 300 source, isolate, encoding, print_tokens || check_tokens, |
| 295 &experimental_tokens, repeat, harmony_settings); | 301 &experimental_tokens, repeat, harmony_settings); |
| 296 break; | 302 break; |
| 297 case UTF8TO16: | 303 } |
| 298 experimental_time = RunExperimentalScanner<uint16_t>( | |
| 299 fname, isolate, encoding, print_tokens || check_tokens, | |
| 300 &experimental_tokens, repeat, harmony_settings); | |
| 301 break; | |
| 302 default: | 304 default: |
| 303 printf("Encoding not supported by the experimental scanner\n"); | 305 printf("Encoding not supported by the experimental scanner\n"); |
| 304 exit(1); | 306 exit(1); |
| 305 break; | 307 break; |
| 306 } | 308 } |
| 307 } | 309 } |
| 308 if (print_tokens && !run_experimental) { | 310 if (print_tokens && !run_experimental) { |
| 309 PrintTokens("Baseline", baseline_tokens); | 311 PrintTokens("Baseline", baseline_tokens); |
| 310 } | 312 } |
| 311 if (print_tokens && !run_baseline) { | 313 if (print_tokens && !run_baseline) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } | 393 } |
| 392 } | 394 } |
| 393 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 395 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 394 { | 396 { |
| 395 v8::HandleScope handle_scope(isolate); | 397 v8::HandleScope handle_scope(isolate); |
| 396 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 398 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
| 397 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | 399 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
| 398 ASSERT(!context.IsEmpty()); | 400 ASSERT(!context.IsEmpty()); |
| 399 { | 401 { |
| 400 v8::Context::Scope scope(context); | 402 v8::Context::Scope scope(context); |
| 401 Isolate* isolate = Isolate::Current(); | 403 Isolate* internal_isolate = Isolate::Current(); |
| 402 double baseline_total = 0, experimental_total = 0; | 404 double baseline_total = 0, experimental_total = 0; |
| 403 for (size_t i = 0; i < fnames.size(); i++) { | 405 for (size_t i = 0; i < fnames.size(); i++) { |
| 404 std::pair<TimeDelta, TimeDelta> times; | 406 std::pair<TimeDelta, TimeDelta> times; |
| 405 check_tokens = check_tokens && run_baseline && run_experimental; | 407 check_tokens = check_tokens && run_baseline && run_experimental; |
| 406 times = ProcessFile(fnames[i].c_str(), encoding, isolate, run_baseline, | 408 times = ProcessFile(fnames[i].c_str(), |
| 407 run_experimental, print_tokens, check_tokens, | 409 encoding, |
| 408 break_after_illegal, repeat, | 410 internal_isolate, |
| 411 run_baseline, |
| 412 run_experimental, |
| 413 print_tokens, |
| 414 check_tokens, |
| 415 break_after_illegal, |
| 416 repeat, |
| 409 harmony_settings); | 417 harmony_settings); |
| 410 baseline_total += times.first.InMillisecondsF(); | 418 baseline_total += times.first.InMillisecondsF(); |
| 411 experimental_total += times.second.InMillisecondsF(); | 419 experimental_total += times.second.InMillisecondsF(); |
| 412 } | 420 } |
| 413 if (run_baseline) { | 421 if (run_baseline) { |
| 414 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(), | 422 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(), |
| 415 baseline_total); | 423 baseline_total); |
| 416 } | 424 } |
| 417 if (run_experimental) { | 425 if (run_experimental) { |
| 418 if (benchmark.empty()) benchmark = "Experimental"; | 426 if (benchmark.empty()) benchmark = "Experimental"; |
| 419 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), | 427 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), |
| 420 experimental_total); | 428 experimental_total); |
| 421 } | 429 } |
| 422 } | 430 } |
| 423 } | 431 } |
| 424 v8::V8::Dispose(); | 432 v8::V8::Dispose(); |
| 425 return 0; | 433 return 0; |
| 426 } | 434 } |
| OLD | NEW |