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

Side by Side Diff: src/lexer/lexer-shell.cc

Issue 71373004: Add a flag to lexer-shell to replicate input file. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 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
« no previous file with comments | « src/lexer/experimental-scanner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 using namespace v8::internal; 50 using namespace v8::internal;
51 51
52 enum Encoding { 52 enum Encoding {
53 LATIN1, 53 LATIN1,
54 UTF8, 54 UTF8,
55 UTF16 55 UTF16
56 }; 56 };
57 57
58 58
59 const byte* ReadFile(const char* name, Isolate* isolate, int* size) {
60 FILE* file = fopen(name, "rb");
61 *size = 0;
62 if (file == NULL) return NULL;
63
64 fseek(file, 0, SEEK_END);
65 *size = ftell(file);
66 rewind(file);
67
68 byte* chars = new byte[*size + 1];
69 chars[*size] = 0;
70 for (int i = 0; i < *size;) {
71 int read = static_cast<int>(fread(&chars[i], 1, *size - i, file));
72 i += read;
73 }
74 fclose(file);
75 return chars;
76 }
77
78 class BaselineScanner { 59 class BaselineScanner {
79 public: 60 public:
80 BaselineScanner(const char* fname, 61 BaselineScanner(const char* fname,
81 Isolate* isolate, 62 Isolate* isolate,
82 Encoding encoding, 63 Encoding encoding,
83 ElapsedTimer* timer) 64 ElapsedTimer* timer,
65 int repeat)
84 : stream_(NULL) { 66 : stream_(NULL) {
85 int length = 0; 67 int length = 0;
86 source_ = ReadFile(fname, isolate, &length); 68 source_ = ReadFile(fname, isolate, &length, repeat);
87 unicode_cache_ = new UnicodeCache(); 69 unicode_cache_ = new UnicodeCache();
88 scanner_ = new Scanner(unicode_cache_); 70 scanner_ = new Scanner(unicode_cache_);
89 switch (encoding) { 71 switch (encoding) {
90 case UTF8: 72 case UTF8:
91 stream_ = new Utf8ToUtf16CharacterStream(source_, length); 73 stream_ = new Utf8ToUtf16CharacterStream(source_, length);
92 break; 74 break;
93 case UTF16: { 75 case UTF16: {
94 Handle<String> result = isolate->factory()->NewStringFromTwoByte( 76 Handle<String> result = isolate->factory()->NewStringFromTwoByte(
95 Vector<const uint16_t>( 77 Vector<const uint16_t>(
96 reinterpret_cast<const uint16_t*>(source_), 78 reinterpret_cast<const uint16_t*>(source_),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 prefix, Token::Name(value), 133 prefix, Token::Name(value),
152 static_cast<int>(beg), static_cast<int>(end)); 134 static_cast<int>(beg), static_cast<int>(end));
153 } 135 }
154 }; 136 };
155 137
156 138
157 TimeDelta RunBaselineScanner(const char* fname, 139 TimeDelta RunBaselineScanner(const char* fname,
158 Isolate* isolate, 140 Isolate* isolate,
159 Encoding encoding, 141 Encoding encoding,
160 bool dump_tokens, 142 bool dump_tokens,
161 std::vector<TokenWithLocation>* tokens) { 143 std::vector<TokenWithLocation>* tokens,
144 int repeat) {
162 ElapsedTimer timer; 145 ElapsedTimer timer;
163 BaselineScanner scanner(fname, isolate, encoding, &timer); 146 BaselineScanner scanner(fname, isolate, encoding, &timer, repeat);
164 Token::Value token; 147 Token::Value token;
165 int beg, end; 148 int beg, end;
166 do { 149 do {
167 token = scanner.Next(&beg, &end); 150 token = scanner.Next(&beg, &end);
168 if (dump_tokens) { 151 if (dump_tokens) {
169 tokens->push_back(TokenWithLocation(token, beg, end)); 152 tokens->push_back(TokenWithLocation(token, beg, end));
170 } 153 }
171 } while (token != Token::EOS); 154 } while (token != Token::EOS);
172 return timer.Elapsed(); 155 return timer.Elapsed();
173 } 156 }
174 157
175 158
176 TimeDelta RunExperimentalScanner(const char* fname, 159 TimeDelta RunExperimentalScanner(const char* fname,
177 Isolate* isolate, 160 Isolate* isolate,
178 Encoding encoding, 161 Encoding encoding,
179 bool dump_tokens, 162 bool dump_tokens,
180 std::vector<TokenWithLocation>* tokens) { 163 std::vector<TokenWithLocation>* tokens,
164 int repeat) {
181 ElapsedTimer timer; 165 ElapsedTimer timer;
166 ExperimentalScanner scanner(fname, true, isolate, repeat);
182 timer.Start(); 167 timer.Start();
183 ExperimentalScanner scanner(fname, true, isolate);
184 Token::Value token; 168 Token::Value token;
185 do { 169 do {
186 token = scanner.Next(); 170 token = scanner.Next();
187 ExperimentalScanner::Location location = scanner.location(); 171 ExperimentalScanner::Location location = scanner.location();
188 if (dump_tokens) { 172 if (dump_tokens) {
189 tokens->push_back( 173 tokens->push_back(
190 TokenWithLocation(token, location.beg_pos, location.end_pos)); 174 TokenWithLocation(token, location.beg_pos, location.end_pos));
191 } 175 }
192 } while (token != Token::EOS); 176 } while (token != Token::EOS);
193 return timer.Elapsed(); 177 return timer.Elapsed();
(...skipping 11 matching lines...) Expand all
205 } 189 }
206 190
207 191
208 std::pair<TimeDelta, TimeDelta> ProcessFile( 192 std::pair<TimeDelta, TimeDelta> ProcessFile(
209 const char* fname, 193 const char* fname,
210 Encoding encoding, 194 Encoding encoding,
211 Isolate* isolate, 195 Isolate* isolate,
212 bool run_baseline, 196 bool run_baseline,
213 bool run_experimental, 197 bool run_experimental,
214 bool print_tokens, 198 bool print_tokens,
215 bool check_tokens) { 199 bool check_tokens,
200 int repeat) {
216 if (print_tokens) { 201 if (print_tokens) {
217 printf("Processing file %s\n", fname); 202 printf("Processing file %s\n", fname);
218 } 203 }
219 HandleScope handle_scope(isolate); 204 HandleScope handle_scope(isolate);
220 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens; 205 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens;
221 TimeDelta baseline_time, experimental_time; 206 TimeDelta baseline_time, experimental_time;
222 if (run_baseline) { 207 if (run_baseline) {
223 baseline_time = RunBaselineScanner( 208 baseline_time = RunBaselineScanner(
224 fname, isolate, encoding, print_tokens || check_tokens, 209 fname, isolate, encoding, print_tokens || check_tokens,
225 &baseline_tokens); 210 &baseline_tokens, repeat);
226 } 211 }
227 if (run_experimental) { 212 if (run_experimental) {
228 experimental_time = RunExperimentalScanner( 213 experimental_time = RunExperimentalScanner(
229 fname, isolate, encoding, print_tokens || check_tokens, 214 fname, isolate, encoding, print_tokens || check_tokens,
230 &experimental_tokens); 215 &experimental_tokens, repeat);
231 } 216 }
232 if (print_tokens && !run_experimental) { 217 if (print_tokens && !run_experimental) {
233 PrintTokens("Baseline", baseline_tokens); 218 PrintTokens("Baseline", baseline_tokens);
234 } 219 }
235 if (print_tokens && !run_baseline) { 220 if (print_tokens && !run_baseline) {
236 PrintTokens("Experimental", experimental_tokens); 221 PrintTokens("Experimental", experimental_tokens);
237 } 222 }
238 if ((print_tokens || check_tokens) && run_baseline && run_experimental) { 223 if ((print_tokens || check_tokens) && run_baseline && run_experimental) {
239 if (print_tokens) { 224 if (print_tokens) {
240 printf("No of tokens in Baseline: %d\n", 225 printf("No of tokens in Baseline: %d\n",
(...skipping 19 matching lines...) Expand all
260 int main(int argc, char* argv[]) { 245 int main(int argc, char* argv[]) {
261 v8::V8::InitializeICU(); 246 v8::V8::InitializeICU();
262 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 247 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
263 Encoding encoding = LATIN1; 248 Encoding encoding = LATIN1;
264 bool print_tokens = false; 249 bool print_tokens = false;
265 bool run_baseline = true; 250 bool run_baseline = true;
266 bool run_experimental = true; 251 bool run_experimental = true;
267 bool check_tokens = true; 252 bool check_tokens = true;
268 std::vector<std::string> fnames; 253 std::vector<std::string> fnames;
269 std::string benchmark; 254 std::string benchmark;
255 int repeat = 1;
270 for (int i = 0; i < argc; ++i) { 256 for (int i = 0; i < argc; ++i) {
271 if (strcmp(argv[i], "--latin1") == 0) { 257 if (strcmp(argv[i], "--latin1") == 0) {
272 encoding = LATIN1; 258 encoding = LATIN1;
273 } else if (strcmp(argv[i], "--utf8") == 0) { 259 } else if (strcmp(argv[i], "--utf8") == 0) {
274 encoding = UTF8; 260 encoding = UTF8;
275 } else if (strcmp(argv[i], "--utf16") == 0) { 261 } else if (strcmp(argv[i], "--utf16") == 0) {
276 encoding = UTF16; 262 encoding = UTF16;
277 } else if (strcmp(argv[i], "--print-tokens") == 0) { 263 } else if (strcmp(argv[i], "--print-tokens") == 0) {
278 print_tokens = true; 264 print_tokens = true;
279 } else if (strcmp(argv[i], "--no-baseline") == 0) { 265 } else if (strcmp(argv[i], "--no-baseline") == 0) {
280 run_baseline = false; 266 run_baseline = false;
281 } else if (strcmp(argv[i], "--no-experimental") == 0) { 267 } else if (strcmp(argv[i], "--no-experimental") == 0) {
282 run_experimental = false; 268 run_experimental = false;
283 } else if (strcmp(argv[i], "--no-check") == 0) { 269 } else if (strcmp(argv[i], "--no-check") == 0) {
284 check_tokens = false; 270 check_tokens = false;
285 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) { 271 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) {
286 benchmark = std::string(argv[i]).substr(12); 272 benchmark = std::string(argv[i]).substr(12);
273 } else if (strncmp(argv[i], "--repeat=", 9) == 0) {
274 std::string repeat_str = std::string(argv[i]).substr(9);
275 repeat = atoi(repeat_str.c_str());
287 } else if (i > 0 && argv[i][0] != '-') { 276 } else if (i > 0 && argv[i][0] != '-') {
288 fnames.push_back(std::string(argv[i])); 277 fnames.push_back(std::string(argv[i]));
289 } 278 }
290 } 279 }
291 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 280 v8::Isolate* isolate = v8::Isolate::GetCurrent();
292 { 281 {
293 v8::HandleScope handle_scope(isolate); 282 v8::HandleScope handle_scope(isolate);
294 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 283 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
295 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); 284 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
296 ASSERT(!context.IsEmpty()); 285 ASSERT(!context.IsEmpty());
297 { 286 {
298 v8::Context::Scope scope(context); 287 v8::Context::Scope scope(context);
299 Isolate* isolate = Isolate::Current(); 288 Isolate* isolate = Isolate::Current();
300 double baseline_total = 0, experimental_total = 0; 289 double baseline_total = 0, experimental_total = 0;
301 for (size_t i = 0; i < fnames.size(); i++) { 290 for (size_t i = 0; i < fnames.size(); i++) {
302 std::pair<TimeDelta, TimeDelta> times; 291 std::pair<TimeDelta, TimeDelta> times;
303 check_tokens = check_tokens && run_baseline && run_experimental; 292 check_tokens = check_tokens && run_baseline && run_experimental;
304 times = ProcessFile(fnames[i].c_str(), encoding, isolate, run_baseline, 293 times = ProcessFile(fnames[i].c_str(), encoding, isolate, run_baseline,
305 run_experimental, print_tokens, check_tokens); 294 run_experimental, print_tokens, check_tokens,
295 repeat);
306 baseline_total += times.first.InMillisecondsF(); 296 baseline_total += times.first.InMillisecondsF();
307 experimental_total += times.second.InMillisecondsF(); 297 experimental_total += times.second.InMillisecondsF();
308 } 298 }
309 if (run_baseline) { 299 if (run_baseline) {
310 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(), 300 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(),
311 baseline_total); 301 baseline_total);
312 } 302 }
313 if (run_experimental) { 303 if (run_experimental) {
314 if (benchmark.empty()) benchmark = "Experimental"; 304 if (benchmark.empty()) benchmark = "Experimental";
315 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), 305 printf("%s(RunTime): %.f ms\n", benchmark.c_str(),
316 experimental_total); 306 experimental_total);
317 } 307 }
318 } 308 }
319 } 309 }
320 v8::V8::Dispose(); 310 v8::V8::Dispose();
321 return 0; 311 return 0;
322 } 312 }
OLDNEW
« no previous file with comments | « src/lexer/experimental-scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698