OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 virtual size_t length() const { return length_; } | 62 virtual size_t length() const { return length_; } |
63 virtual const char* data() const { return data_; } | 63 virtual const char* data() const { return data_; } |
64 | 64 |
65 private: | 65 private: |
66 const char* data_; | 66 const char* data_; |
67 int length_; | 67 int length_; |
68 }; | 68 }; |
69 | 69 |
70 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser( | 70 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser( |
71 const char* fname, Encoding encoding, int repeat, v8::Isolate* isolate, | 71 const char* fname, Encoding encoding, int repeat, v8::Isolate* isolate, |
72 v8::Handle<v8::Context> context) { | 72 v8::Local<v8::Context> context) { |
73 int length = 0; | 73 int length = 0; |
74 const byte* source = ReadFileAndRepeat(fname, &length, repeat); | 74 const byte* source = ReadFileAndRepeat(fname, &length, repeat); |
75 v8::Handle<v8::String> source_handle; | 75 v8::Local<v8::String> source_handle; |
76 switch (encoding) { | 76 switch (encoding) { |
77 case UTF8: { | 77 case UTF8: { |
78 source_handle = v8::String::NewFromUtf8( | 78 source_handle = v8::String::NewFromUtf8( |
79 isolate, reinterpret_cast<const char*>(source)); | 79 isolate, reinterpret_cast<const char*>(source), |
| 80 v8::NewStringType::kNormal).ToLocalChecked(); |
80 break; | 81 break; |
81 } | 82 } |
82 case UTF16: { | 83 case UTF16: { |
83 source_handle = v8::String::NewFromTwoByte( | 84 source_handle = |
84 isolate, reinterpret_cast<const uint16_t*>(source), | 85 v8::String::NewFromTwoByte( |
85 v8::String::kNormalString, length / 2); | 86 isolate, reinterpret_cast<const uint16_t*>(source), |
| 87 v8::NewStringType::kNormal, length / 2).ToLocalChecked(); |
86 break; | 88 break; |
87 } | 89 } |
88 case LATIN1: { | 90 case LATIN1: { |
89 StringResource8* string_resource = | 91 StringResource8* string_resource = |
90 new StringResource8(reinterpret_cast<const char*>(source), length); | 92 new StringResource8(reinterpret_cast<const char*>(source), length); |
91 source_handle = v8::String::NewExternal(isolate, string_resource); | 93 source_handle = v8::String::NewExternalOneByte(isolate, string_resource) |
| 94 .ToLocalChecked(); |
92 break; | 95 break; |
93 } | 96 } |
94 } | 97 } |
95 v8::base::TimeDelta parse_time1, parse_time2; | 98 v8::base::TimeDelta parse_time1, parse_time2; |
96 Handle<Script> script = | 99 Handle<Script> script = |
97 reinterpret_cast<i::Isolate*>(isolate)->factory()->NewScript( | 100 reinterpret_cast<i::Isolate*>(isolate)->factory()->NewScript( |
98 v8::Utils::OpenHandle(*source_handle)); | 101 v8::Utils::OpenHandle(*source_handle)); |
99 i::ScriptData* cached_data_impl = NULL; | 102 i::ScriptData* cached_data_impl = NULL; |
100 // First round of parsing (produce data to cache). | 103 // First round of parsing (produce data to cache). |
101 { | 104 { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 fnames.push_back(std::string(argv[i])); | 166 fnames.push_back(std::string(argv[i])); |
164 } | 167 } |
165 } | 168 } |
166 ArrayBufferAllocator array_buffer_allocator; | 169 ArrayBufferAllocator array_buffer_allocator; |
167 v8::Isolate::CreateParams create_params; | 170 v8::Isolate::CreateParams create_params; |
168 create_params.array_buffer_allocator = &array_buffer_allocator; | 171 create_params.array_buffer_allocator = &array_buffer_allocator; |
169 v8::Isolate* isolate = v8::Isolate::New(create_params); | 172 v8::Isolate* isolate = v8::Isolate::New(create_params); |
170 { | 173 { |
171 v8::Isolate::Scope isolate_scope(isolate); | 174 v8::Isolate::Scope isolate_scope(isolate); |
172 v8::HandleScope handle_scope(isolate); | 175 v8::HandleScope handle_scope(isolate); |
173 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); | 176 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); |
174 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | 177 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
175 DCHECK(!context.IsEmpty()); | 178 DCHECK(!context.IsEmpty()); |
176 { | 179 { |
177 v8::Context::Scope scope(context); | 180 v8::Context::Scope scope(context); |
178 double first_parse_total = 0; | 181 double first_parse_total = 0; |
179 double second_parse_total = 0; | 182 double second_parse_total = 0; |
180 for (size_t i = 0; i < fnames.size(); i++) { | 183 for (size_t i = 0; i < fnames.size(); i++) { |
181 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time = | 184 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time = |
182 RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate, | 185 RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate, |
183 context); | 186 context); |
184 first_parse_total += time.first.InMillisecondsF(); | 187 first_parse_total += time.first.InMillisecondsF(); |
185 second_parse_total += time.second.InMillisecondsF(); | 188 second_parse_total += time.second.InMillisecondsF(); |
186 } | 189 } |
187 if (benchmark.empty()) benchmark = "Baseline"; | 190 if (benchmark.empty()) benchmark = "Baseline"; |
188 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), | 191 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), |
189 first_parse_total); | 192 first_parse_total); |
190 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), | 193 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), |
191 second_parse_total); | 194 second_parse_total); |
192 } | 195 } |
193 } | 196 } |
194 v8::V8::Dispose(); | 197 v8::V8::Dispose(); |
195 v8::V8::ShutdownPlatform(); | 198 v8::V8::ShutdownPlatform(); |
196 delete platform; | 199 delete platform; |
197 return 0; | 200 return 0; |
198 } | 201 } |
OLD | NEW |