| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 return std::make_pair(parse_time1, parse_time2); | 135 return std::make_pair(parse_time1, parse_time2); |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 int main(int argc, char* argv[]) { | 139 int main(int argc, char* argv[]) { |
| 140 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 140 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 141 v8::V8::InitializeICU(); | 141 v8::V8::InitializeICU(); |
| 142 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); | 142 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 143 v8::V8::InitializePlatform(platform); | 143 v8::V8::InitializePlatform(platform); |
| 144 ArrayBufferAllocator array_buffer_allocator; | |
| 145 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); | |
| 146 v8::V8::Initialize(); | 144 v8::V8::Initialize(); |
| 147 Encoding encoding = LATIN1; | 145 Encoding encoding = LATIN1; |
| 148 std::vector<std::string> fnames; | 146 std::vector<std::string> fnames; |
| 149 std::string benchmark; | 147 std::string benchmark; |
| 150 int repeat = 1; | 148 int repeat = 1; |
| 151 for (int i = 0; i < argc; ++i) { | 149 for (int i = 0; i < argc; ++i) { |
| 152 if (strcmp(argv[i], "--latin1") == 0) { | 150 if (strcmp(argv[i], "--latin1") == 0) { |
| 153 encoding = LATIN1; | 151 encoding = LATIN1; |
| 154 } else if (strcmp(argv[i], "--utf8") == 0) { | 152 } else if (strcmp(argv[i], "--utf8") == 0) { |
| 155 encoding = UTF8; | 153 encoding = UTF8; |
| 156 } else if (strcmp(argv[i], "--utf16") == 0) { | 154 } else if (strcmp(argv[i], "--utf16") == 0) { |
| 157 encoding = UTF16; | 155 encoding = UTF16; |
| 158 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) { | 156 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) { |
| 159 benchmark = std::string(argv[i]).substr(12); | 157 benchmark = std::string(argv[i]).substr(12); |
| 160 } else if (strncmp(argv[i], "--repeat=", 9) == 0) { | 158 } else if (strncmp(argv[i], "--repeat=", 9) == 0) { |
| 161 std::string repeat_str = std::string(argv[i]).substr(9); | 159 std::string repeat_str = std::string(argv[i]).substr(9); |
| 162 repeat = atoi(repeat_str.c_str()); | 160 repeat = atoi(repeat_str.c_str()); |
| 163 } else if (i > 0 && argv[i][0] != '-') { | 161 } else if (i > 0 && argv[i][0] != '-') { |
| 164 fnames.push_back(std::string(argv[i])); | 162 fnames.push_back(std::string(argv[i])); |
| 165 } | 163 } |
| 166 } | 164 } |
| 167 v8::Isolate* isolate = v8::Isolate::New(); | 165 ArrayBufferAllocator array_buffer_allocator; |
| 166 v8::Isolate::CreateParams create_params; |
| 167 create_params.array_buffer_allocator = &array_buffer_allocator; |
| 168 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 168 { | 169 { |
| 169 v8::Isolate::Scope isolate_scope(isolate); | 170 v8::Isolate::Scope isolate_scope(isolate); |
| 170 v8::HandleScope handle_scope(isolate); | 171 v8::HandleScope handle_scope(isolate); |
| 171 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); | 172 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); |
| 172 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | 173 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
| 173 DCHECK(!context.IsEmpty()); | 174 DCHECK(!context.IsEmpty()); |
| 174 { | 175 { |
| 175 v8::Context::Scope scope(context); | 176 v8::Context::Scope scope(context); |
| 176 double first_parse_total = 0; | 177 double first_parse_total = 0; |
| 177 double second_parse_total = 0; | 178 double second_parse_total = 0; |
| 178 for (size_t i = 0; i < fnames.size(); i++) { | 179 for (size_t i = 0; i < fnames.size(); i++) { |
| 179 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time = | 180 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time = |
| 180 RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate, | 181 RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate, |
| 181 context); | 182 context); |
| 182 first_parse_total += time.first.InMillisecondsF(); | 183 first_parse_total += time.first.InMillisecondsF(); |
| 183 second_parse_total += time.second.InMillisecondsF(); | 184 second_parse_total += time.second.InMillisecondsF(); |
| 184 } | 185 } |
| 185 if (benchmark.empty()) benchmark = "Baseline"; | 186 if (benchmark.empty()) benchmark = "Baseline"; |
| 186 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), | 187 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), |
| 187 first_parse_total); | 188 first_parse_total); |
| 188 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), | 189 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), |
| 189 second_parse_total); | 190 second_parse_total); |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 v8::V8::Dispose(); | 193 v8::V8::Dispose(); |
| 193 v8::V8::ShutdownPlatform(); | 194 v8::V8::ShutdownPlatform(); |
| 194 delete platform; | 195 delete platform; |
| 195 return 0; | 196 return 0; |
| 196 } | 197 } |
| OLD | NEW |