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

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

Issue 49303003: Experimental parser: measurement fixes in lexer-shell. (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 | « no previous file | 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 for (int i = 0; i < *size;) { 70 for (int i = 0; i < *size;) {
71 int read = static_cast<int>(fread(&chars[i], 1, *size - i, file)); 71 int read = static_cast<int>(fread(&chars[i], 1, *size - i, file));
72 i += read; 72 i += read;
73 } 73 }
74 fclose(file); 74 fclose(file);
75 return chars; 75 return chars;
76 } 76 }
77 77
78 class BaselineScanner { 78 class BaselineScanner {
79 public: 79 public:
80 BaselineScanner(const char* fname, Isolate* isolate, Encoding encoding) { 80 BaselineScanner(const char* fname,
81 Isolate* isolate,
82 Encoding encoding,
83 ElapsedTimer* timer) {
81 int length = 0; 84 int length = 0;
82 source_ = ReadFile(fname, isolate, &length); 85 source_ = ReadFile(fname, isolate, &length);
83 unicode_cache_ = new UnicodeCache(); 86 unicode_cache_ = new UnicodeCache();
84 scanner_ = new Scanner(unicode_cache_); 87 scanner_ = new Scanner(unicode_cache_);
85 switch (encoding) { 88 switch (encoding) {
86 case ASCII: 89 case ASCII:
87 case UTF8: 90 case UTF8:
88 stream_ = new Utf8ToUtf16CharacterStream(source_, length); 91 stream_ = new Utf8ToUtf16CharacterStream(source_, length);
89 break; 92 break;
90 case UTF16: { 93 case UTF16: {
91 Handle<String> result = isolate->factory()->NewStringFromTwoByte( 94 Handle<String> result = isolate->factory()->NewStringFromTwoByte(
92 Vector<const uint16_t>( 95 Vector<const uint16_t>(
93 reinterpret_cast<const uint16_t*>(source_), 96 reinterpret_cast<const uint16_t*>(source_),
94 length / 2)); 97 length / 2));
95 stream_ = 98 stream_ =
96 new GenericStringUtf16CharacterStream(result, 0, result->length()); 99 new GenericStringUtf16CharacterStream(result, 0, result->length());
97 break; 100 break;
98 } 101 }
99 case LATIN1: { 102 case LATIN1: {
100 Handle<String> result = isolate->factory()->NewStringFromOneByte( 103 Handle<String> result = isolate->factory()->NewStringFromOneByte(
101 Vector<const uint8_t>(source_, length)); 104 Vector<const uint8_t>(source_, length));
102 stream_ = 105 stream_ =
103 new GenericStringUtf16CharacterStream(result, 0, result->length()); 106 new GenericStringUtf16CharacterStream(result, 0, result->length());
104 break; 107 break;
105 } 108 }
106 default: 109 default:
107 break; 110 break;
108 } 111 }
112 timer->Start();
109 scanner_->Initialize(stream_); 113 scanner_->Initialize(stream_);
110 } 114 }
111 115
112 ~BaselineScanner() { 116 ~BaselineScanner() {
113 delete scanner_; 117 delete scanner_;
114 delete stream_; 118 delete stream_;
115 delete unicode_cache_; 119 delete unicode_cache_;
116 delete[] source_; 120 delete[] source_;
117 } 121 }
118 122
(...skipping 10 matching lines...) Expand all
129 const byte* source_; 133 const byte* source_;
130 BufferedUtf16CharacterStream* stream_; 134 BufferedUtf16CharacterStream* stream_;
131 }; 135 };
132 136
133 137
134 int main(int argc, char* argv[]) { 138 int main(int argc, char* argv[]) {
135 v8::V8::InitializeICU(); 139 v8::V8::InitializeICU();
136 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 140 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
137 Encoding encoding = ASCII; 141 Encoding encoding = ASCII;
138 bool print_baseline = false; 142 bool print_baseline = false;
143 bool run_baseline = true;
144 bool run_experimental = true;
139 for (int i = 0; i < argc; ++i) { 145 for (int i = 0; i < argc; ++i) {
140 if (strcmp(argv[i], "--latin1") == 0) { 146 if (strcmp(argv[i], "--latin1") == 0) {
141 encoding = LATIN1; 147 encoding = LATIN1;
142 } else if (strcmp(argv[i], "--utf8") == 0) { 148 } else if (strcmp(argv[i], "--utf8") == 0) {
143 encoding = UTF8; 149 encoding = UTF8;
144 } else if (strcmp(argv[i], "--utf16") == 0) { 150 } else if (strcmp(argv[i], "--utf16") == 0) {
145 encoding = UTF16; 151 encoding = UTF16;
146 } else if (strcmp(argv[i], "--ascii") == 0) { 152 } else if (strcmp(argv[i], "--ascii") == 0) {
147 encoding = ASCII; 153 encoding = ASCII;
148 } else if (strcmp(argv[i], "--print-baseline") == 0) { 154 } else if (strcmp(argv[i], "--print-baseline") == 0) {
149 print_baseline = true; 155 print_baseline = true;
156 } else if (strcmp(argv[i], "--no-baseline") == 0) {
157 run_baseline = false;
158 } else if (strcmp(argv[i], "--no-experimental") == 0) {
159 run_experimental = false;
150 } 160 }
151 } 161 }
152 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 162 v8::Isolate* isolate = v8::Isolate::GetCurrent();
153 { 163 {
154 v8::HandleScope handle_scope(isolate); 164 v8::HandleScope handle_scope(isolate);
155 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 165 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
156 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); 166 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
157 ASSERT(!context.IsEmpty()); 167 ASSERT(!context.IsEmpty());
158 { 168 {
159 v8::Context::Scope scope(context); 169 v8::Context::Scope scope(context);
160 Isolate* isolate = Isolate::Current(); 170 Isolate* isolate = Isolate::Current();
161 HandleScope handle_scope(isolate); 171 HandleScope handle_scope(isolate);
162 BaselineScanner baseline(argv[1], isolate, encoding);
163 ExperimentalScanner experimental(argv[1], true, isolate);
164 172
165 std::vector<Token::Value> baseline_tokens, experimental_tokens; 173 std::vector<Token::Value> baseline_tokens, experimental_tokens;
166 std::vector<size_t> baseline_beg, baseline_end, experimental_beg, 174 std::vector<size_t> baseline_beg, baseline_end, experimental_beg,
167 experimental_end; 175 experimental_end;
168 Token::Value token; 176 Token::Value token;
169 int beg, end; 177 int beg, end;
170 178
171 TimeDelta baseline_time, experimental_time; 179 TimeDelta baseline_time, experimental_time;
172 ElapsedTimer timer; 180 ElapsedTimer timer;
173 { 181 if (run_baseline) {
174 timer.Start(); 182 BaselineScanner baseline(argv[1], isolate, encoding, &timer);
175 do { 183 do {
176 token = baseline.Next(&beg, &end); 184 token = baseline.Next(&beg, &end);
177 baseline_tokens.push_back(token); 185 baseline_tokens.push_back(token);
178 baseline_beg.push_back(beg); 186 baseline_beg.push_back(beg);
179 baseline_end.push_back(end); 187 baseline_end.push_back(end);
180 } while (token != Token::EOS); 188 } while (token != Token::EOS);
181 baseline_time = timer.Elapsed(); 189 baseline_time = timer.Elapsed();
182 } 190 }
183 191
184 { 192 if (run_experimental) {
193 ExperimentalScanner experimental(argv[1], true, isolate);
185 timer.Start(); 194 timer.Start();
186 do { 195 do {
187 token = experimental.Next(); 196 token = experimental.Next();
188 experimental_tokens.push_back(token); 197 experimental_tokens.push_back(token);
189 ExperimentalScanner::Location location = experimental.location(); 198 ExperimentalScanner::Location location = experimental.location();
190 experimental_beg.push_back(location.beg_pos); 199 experimental_beg.push_back(location.beg_pos);
191 experimental_end.push_back(location.end_pos); 200 experimental_end.push_back(location.end_pos);
192 } while (token != Token::EOS); 201 } while (token != Token::EOS);
193 experimental_time = timer.Elapsed(); 202 experimental_time = timer.Elapsed();
194 } 203 }
195 204
196 if (print_baseline) { 205 if (print_baseline) {
197 printf("Baseline:\n"); 206 printf("Baseline:\n");
198 for (size_t i = 0; i < baseline_tokens.size(); ++i) { 207 for (size_t i = 0; i < baseline_tokens.size(); ++i) {
199 printf("=> %11s at (%d, %d)\n", 208 printf("=> %11s at (%d, %d)\n",
200 Token::Name(baseline_tokens[i]), 209 Token::Name(baseline_tokens[i]),
201 static_cast<int>(baseline_beg[i]), 210 static_cast<int>(baseline_beg[i]),
202 static_cast<int>(baseline_end[i])); 211 static_cast<int>(baseline_end[i]));
203 } 212 }
204 printf("(Mis)matches:\n"); 213 printf("(Mis)matches:\n");
205 } 214 }
206 215
207 for (size_t i = 0; i < experimental_tokens.size(); ++i) { 216 if (run_baseline && run_experimental) {
208 printf("=> %11s at (%d, %d)\n", 217 for (size_t i = 0; i < experimental_tokens.size(); ++i) {
209 Token::Name(experimental_tokens[i]), 218 printf("=> %11s at (%d, %d)\n",
210 static_cast<int>(experimental_beg[i]),
211 static_cast<int>(experimental_end[i]));
212 if (experimental_tokens[i] != baseline_tokens[i] ||
213 experimental_beg[i] != baseline_beg[i] ||
214 experimental_end[i] != baseline_end[i]) {
215 printf("MISMATCH:\n");
216 printf("Expected: %s at (%d, %d)\n",
217 Token::Name(baseline_tokens[i]),
218 static_cast<int>(baseline_beg[i]),
219 static_cast<int>(baseline_end[i]));
220 printf("Actual: %s at (%d, %d)\n",
221 Token::Name(experimental_tokens[i]), 219 Token::Name(experimental_tokens[i]),
222 static_cast<int>(experimental_beg[i]), 220 static_cast<int>(experimental_beg[i]),
223 static_cast<int>(experimental_end[i])); 221 static_cast<int>(experimental_end[i]));
224 return 1; 222 if (experimental_tokens[i] != baseline_tokens[i] ||
223 experimental_beg[i] != baseline_beg[i] ||
224 experimental_end[i] != baseline_end[i]) {
225 printf("MISMATCH:\n");
226 printf("Expected: %s at (%d, %d)\n",
227 Token::Name(baseline_tokens[i]),
228 static_cast<int>(baseline_beg[i]),
229 static_cast<int>(baseline_end[i]));
230 printf("Actual: %s at (%d, %d)\n",
231 Token::Name(experimental_tokens[i]),
232 static_cast<int>(experimental_beg[i]),
233 static_cast<int>(experimental_end[i]));
234 return 1;
235 }
225 } 236 }
226 } 237 }
227 printf("No of tokens: %d\n", 238 printf("No of tokens: %d\n",
228 static_cast<int>(experimental_tokens.size())); 239 static_cast<int>(experimental_tokens.size()));
229 printf("Baseline: %f ms\nExperimental %f ms\n", 240 printf("Baseline: %f ms\nExperimental %f ms\n",
230 baseline_time.InMillisecondsF(), 241 baseline_time.InMillisecondsF(),
231 experimental_time.InMillisecondsF()); 242 experimental_time.InMillisecondsF());
232 } 243 }
233 } 244 }
234 v8::V8::Dispose(); 245 v8::V8::Dispose();
235 return 0; 246 return 0;
236 } 247 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698