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

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

Issue 59533005: Prepare lexer-shell for benchmarking: process multiple input files, adjust output. (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/lexer.re ('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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <assert.h> 28 #include <assert.h>
29 #include <fcntl.h> 29 #include <fcntl.h>
30 #include <string.h> 30 #include <string.h>
31 #include <stdio.h> 31 #include <stdio.h>
32 #include <stdlib.h> 32 #include <stdlib.h>
33 #include <string>
33 #include "v8.h" 34 #include "v8.h"
34 35
35 #include "api.h" 36 #include "api.h"
36 #include "ast.h" 37 #include "ast.h"
37 #include "char-predicates-inl.h" 38 #include "char-predicates-inl.h"
38 #include "messages.h" 39 #include "messages.h"
39 #include "platform.h" 40 #include "platform.h"
40 #include "runtime.h" 41 #include "runtime.h"
41 #include "scanner-character-streams.h" 42 #include "scanner-character-streams.h"
42 #include "scopeinfo.h" 43 #include "scopeinfo.h"
(...skipping 30 matching lines...) Expand all
73 } 74 }
74 fclose(file); 75 fclose(file);
75 return chars; 76 return chars;
76 } 77 }
77 78
78 class BaselineScanner { 79 class BaselineScanner {
79 public: 80 public:
80 BaselineScanner(const char* fname, 81 BaselineScanner(const char* fname,
81 Isolate* isolate, 82 Isolate* isolate,
82 Encoding encoding, 83 Encoding encoding,
83 ElapsedTimer* timer) { 84 ElapsedTimer* timer) : stream_(NULL) {
84 int length = 0; 85 int length = 0;
85 source_ = ReadFile(fname, isolate, &length); 86 source_ = ReadFile(fname, isolate, &length);
86 unicode_cache_ = new UnicodeCache(); 87 unicode_cache_ = new UnicodeCache();
87 scanner_ = new Scanner(unicode_cache_); 88 scanner_ = new Scanner(unicode_cache_);
88 switch (encoding) { 89 switch (encoding) {
89 case ASCII: 90 case ASCII:
90 case UTF8: 91 case UTF8:
91 stream_ = new Utf8ToUtf16CharacterStream(source_, length); 92 stream_ = new Utf8ToUtf16CharacterStream(source_, length);
92 break; 93 break;
93 case UTF16: { 94 case UTF16: {
94 Handle<String> result = isolate->factory()->NewStringFromTwoByte( 95 Handle<String> result = isolate->factory()->NewStringFromTwoByte(
95 Vector<const uint16_t>( 96 Vector<const uint16_t>(
96 reinterpret_cast<const uint16_t*>(source_), 97 reinterpret_cast<const uint16_t*>(source_),
97 length / 2)); 98 length / 2));
98 stream_ = 99 stream_ =
99 new GenericStringUtf16CharacterStream(result, 0, result->length()); 100 new GenericStringUtf16CharacterStream(result, 0, result->length());
100 break; 101 break;
101 } 102 }
102 case LATIN1: { 103 case LATIN1: {
103 Handle<String> result = isolate->factory()->NewStringFromOneByte( 104 Handle<String> result = isolate->factory()->NewStringFromOneByte(
104 Vector<const uint8_t>(source_, length)); 105 Vector<const uint8_t>(source_, length));
105 stream_ = 106 stream_ =
106 new GenericStringUtf16CharacterStream(result, 0, result->length()); 107 new GenericStringUtf16CharacterStream(result, 0, result->length());
107 break; 108 break;
108 } 109 }
109 default:
110 break;
111 } 110 }
112 timer->Start(); 111 timer->Start();
113 scanner_->Initialize(stream_); 112 scanner_->Initialize(stream_);
114 } 113 }
115 114
116 ~BaselineScanner() { 115 ~BaselineScanner() {
117 delete scanner_; 116 delete scanner_;
118 delete stream_; 117 delete stream_;
119 delete unicode_cache_; 118 delete unicode_cache_;
120 delete[] source_; 119 delete[] source_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const std::vector<TokenWithLocation>& tokens) { 199 const std::vector<TokenWithLocation>& tokens) {
201 printf("No of tokens: %d\n", 200 printf("No of tokens: %d\n",
202 static_cast<int>(tokens.size())); 201 static_cast<int>(tokens.size()));
203 printf("%s:\n", name); 202 printf("%s:\n", name);
204 for (size_t i = 0; i < tokens.size(); ++i) { 203 for (size_t i = 0; i < tokens.size(); ++i) {
205 tokens[i].Print("=>"); 204 tokens[i].Print("=>");
206 } 205 }
207 } 206 }
208 207
209 208
209 std::pair<TimeDelta, TimeDelta> ProcessFile(
210 const char* fname,
211 Encoding encoding,
212 Isolate* isolate,
213 bool run_baseline,
214 bool run_experimental,
215 bool print_tokens) {
216 if (print_tokens) {
217 printf("Processing file %s\n", fname);
218 }
219 HandleScope handle_scope(isolate);
220 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens;
221 TimeDelta baseline_time, experimental_time;
222 if (run_baseline) {
223 baseline_time = RunBaselineScanner(
224 fname, isolate, encoding, print_tokens, &baseline_tokens);
225 }
226 if (run_experimental) {
227 experimental_time = RunExperimentalScanner(
228 fname, isolate, encoding, print_tokens, &experimental_tokens);
229 }
230 if (print_tokens && !run_experimental) {
231 PrintTokens("Baseline", baseline_tokens);
232 }
233 if (print_tokens && !run_baseline) {
234 PrintTokens("Experimental", experimental_tokens);
235 }
236 if (print_tokens && run_baseline && run_experimental) {
237 printf("No of tokens in Baseline: %d\n",
238 static_cast<int>(baseline_tokens.size()));
239 printf("No of tokens in Experimental: %d\n",
240 static_cast<int>(experimental_tokens.size()));
241 printf("Baseline and Experimental:\n");
242 for (size_t i = 0; i < experimental_tokens.size(); ++i) {
243 experimental_tokens[i].Print("=>");
244 if (experimental_tokens[i] != baseline_tokens[i]) {
245 printf("MISMATCH:\n");
246 baseline_tokens[i].Print("Expected: ");
247 experimental_tokens[i].Print("Actual: ");
248 exit(1);
249 }
250 }
251 }
252 return std::make_pair(baseline_time, experimental_time);
253 }
254
255
210 int main(int argc, char* argv[]) { 256 int main(int argc, char* argv[]) {
211 v8::V8::InitializeICU(); 257 v8::V8::InitializeICU();
212 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 258 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
213 Encoding encoding = ASCII; 259 Encoding encoding = ASCII;
214 bool print_tokens = false; 260 bool print_tokens = false;
215 bool run_baseline = true; 261 bool run_baseline = true;
216 bool run_experimental = true; 262 bool run_experimental = true;
217 char* fname = argv[1]; 263 std::vector<std::string> fnames;
264 std::string benchmark;
218 for (int i = 0; i < argc; ++i) { 265 for (int i = 0; i < argc; ++i) {
219 if (strcmp(argv[i], "--latin1") == 0) { 266 if (strcmp(argv[i], "--latin1") == 0) {
220 encoding = LATIN1; 267 encoding = LATIN1;
221 } else if (strcmp(argv[i], "--utf8") == 0) { 268 } else if (strcmp(argv[i], "--utf8") == 0) {
222 encoding = UTF8; 269 encoding = UTF8;
223 } else if (strcmp(argv[i], "--utf16") == 0) { 270 } else if (strcmp(argv[i], "--utf16") == 0) {
224 encoding = UTF16; 271 encoding = UTF16;
225 } else if (strcmp(argv[i], "--ascii") == 0) { 272 } else if (strcmp(argv[i], "--ascii") == 0) {
226 encoding = ASCII; 273 encoding = ASCII;
227 } else if (strcmp(argv[i], "--print-tokens") == 0) { 274 } else if (strcmp(argv[i], "--print-tokens") == 0) {
228 print_tokens = true; 275 print_tokens = true;
229 } else if (strcmp(argv[i], "--no-baseline") == 0) { 276 } else if (strcmp(argv[i], "--no-baseline") == 0) {
230 run_baseline = false; 277 run_baseline = false;
231 } else if (strcmp(argv[i], "--no-experimental") == 0) { 278 } else if (strcmp(argv[i], "--no-experimental") == 0) {
232 run_experimental = false; 279 run_experimental = false;
233 } else if (argv[i][0] != '-') { 280 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) {
234 fname = argv[i]; 281 benchmark = std::string(argv[1]).substr(12);
282 } else if (i > 0 && argv[i][0] != '-') {
283 fnames.push_back(std::string(argv[i]));
235 } 284 }
236 } 285 }
237 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 286 v8::Isolate* isolate = v8::Isolate::GetCurrent();
238 { 287 {
239 v8::HandleScope handle_scope(isolate); 288 v8::HandleScope handle_scope(isolate);
240 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 289 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
241 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); 290 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
242 ASSERT(!context.IsEmpty()); 291 ASSERT(!context.IsEmpty());
243 { 292 {
244 v8::Context::Scope scope(context); 293 v8::Context::Scope scope(context);
245 Isolate* isolate = Isolate::Current(); 294 Isolate* isolate = Isolate::Current();
246 HandleScope handle_scope(isolate); 295 double baseline_total = 0, experimental_total = 0;
247 296 for (size_t i = 0; i < fnames.size(); i++) {
248 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens; 297 std::pair<TimeDelta, TimeDelta> times;
249 TimeDelta baseline_time, experimental_time; 298 times = ProcessFile(fnames[i].c_str(), encoding, isolate,
299 run_baseline, run_experimental, print_tokens);
300 baseline_total += times.first.InMillisecondsF();
301 experimental_total += times.second.InMillisecondsF();
302 }
250 if (run_baseline) { 303 if (run_baseline) {
251 baseline_time = RunBaselineScanner( 304 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(),
252 fname, isolate, encoding, print_tokens, &baseline_tokens); 305 baseline_total);
253 } 306 }
254 if (run_experimental) { 307 if (run_experimental) {
255 experimental_time = RunExperimentalScanner( 308 printf("Experimental%s(RunTime): %.f ms\n", benchmark.c_str(),
256 fname, isolate, encoding, print_tokens, &experimental_tokens); 309 experimental_total);
257 }
258 if (print_tokens && !run_experimental) {
259 PrintTokens("Baseline", baseline_tokens);
260 }
261 if (print_tokens && !run_baseline) {
262 PrintTokens("Experimental", experimental_tokens);
263 }
264 if (print_tokens && run_baseline && run_experimental) {
265 printf("No of tokens in Baseline: %d\n",
266 static_cast<int>(baseline_tokens.size()));
267 printf("No of tokens in Experimental: %d\n",
268 static_cast<int>(experimental_tokens.size()));
269 printf("Baseline and Experimental:\n");
270 for (size_t i = 0; i < experimental_tokens.size(); ++i) {
271 experimental_tokens[i].Print("=>");
272 if (experimental_tokens[i] != baseline_tokens[i]) {
273 printf("MISMATCH:\n");
274 baseline_tokens[i].Print("Expected: ");
275 experimental_tokens[i].Print("Actual: ");
276 return 1;
277 }
278 }
279 }
280 if (run_baseline) {
281 printf("Baseline : %.3f ms\n", baseline_time.InMillisecondsF());
282 }
283 if (run_experimental) {
284 printf("Experimental: %.3f ms\n", experimental_time.InMillisecondsF());
285 } 310 }
286 } 311 }
287 } 312 }
288 v8::V8::Dispose(); 313 v8::V8::Dispose();
289 return 0; 314 return 0;
290 } 315 }
OLDNEW
« no previous file with comments | « src/lexer/lexer.re ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698