OLD | NEW |
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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #include <assert.h> | 28 #include <assert.h> |
29 #include <string.h> | 29 #include <string.h> |
30 #include <stdio.h> | 30 #include <stdio.h> |
31 #include <stdlib.h> | 31 #include <stdlib.h> |
32 #include <string> | 32 #include <string> |
33 #include <vector> | 33 #include <vector> |
34 #include "src/v8.h" | 34 #include "src/v8.h" |
35 | 35 |
36 #include "src/api.h" | 36 #include "src/api.h" |
| 37 #include "src/base/platform/platform.h" |
37 #include "src/messages.h" | 38 #include "src/messages.h" |
38 #include "src/platform.h" | |
39 #include "src/runtime.h" | 39 #include "src/runtime.h" |
40 #include "src/scanner-character-streams.h" | 40 #include "src/scanner-character-streams.h" |
41 #include "src/scopeinfo.h" | 41 #include "src/scopeinfo.h" |
42 #include "tools/shell-utils.h" | 42 #include "tools/shell-utils.h" |
43 #include "src/string-stream.h" | 43 #include "src/string-stream.h" |
44 #include "src/scanner.h" | 44 #include "src/scanner.h" |
45 | 45 |
46 | 46 |
47 using namespace v8::internal; | 47 using namespace v8::internal; |
48 | 48 |
49 | 49 |
50 class BaselineScanner { | 50 class BaselineScanner { |
51 public: | 51 public: |
52 BaselineScanner(const char* fname, | 52 BaselineScanner(const char* fname, |
53 Isolate* isolate, | 53 Isolate* isolate, |
54 Encoding encoding, | 54 Encoding encoding, |
55 ElapsedTimer* timer, | 55 v8::base::ElapsedTimer* timer, |
56 int repeat) | 56 int repeat) |
57 : stream_(NULL) { | 57 : stream_(NULL) { |
58 int length = 0; | 58 int length = 0; |
59 source_ = ReadFileAndRepeat(fname, &length, repeat); | 59 source_ = ReadFileAndRepeat(fname, &length, repeat); |
60 unicode_cache_ = new UnicodeCache(); | 60 unicode_cache_ = new UnicodeCache(); |
61 scanner_ = new Scanner(unicode_cache_); | 61 scanner_ = new Scanner(unicode_cache_); |
62 switch (encoding) { | 62 switch (encoding) { |
63 case UTF8: | 63 case UTF8: |
64 stream_ = new Utf8ToUtf16CharacterStream(source_, length); | 64 stream_ = new Utf8ToUtf16CharacterStream(source_, length); |
65 break; | 65 break; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return !(*this == other); | 120 return !(*this == other); |
121 } | 121 } |
122 void Print(const char* prefix) const { | 122 void Print(const char* prefix) const { |
123 printf("%s %11s at (%d, %d)\n", | 123 printf("%s %11s at (%d, %d)\n", |
124 prefix, Token::Name(value), | 124 prefix, Token::Name(value), |
125 static_cast<int>(beg), static_cast<int>(end)); | 125 static_cast<int>(beg), static_cast<int>(end)); |
126 } | 126 } |
127 }; | 127 }; |
128 | 128 |
129 | 129 |
130 TimeDelta RunBaselineScanner(const char* fname, | 130 v8::base::TimeDelta RunBaselineScanner(const char* fname, Isolate* isolate, |
131 Isolate* isolate, | 131 Encoding encoding, bool dump_tokens, |
132 Encoding encoding, | 132 std::vector<TokenWithLocation>* tokens, |
133 bool dump_tokens, | 133 int repeat) { |
134 std::vector<TokenWithLocation>* tokens, | 134 v8::base::ElapsedTimer timer; |
135 int repeat) { | |
136 ElapsedTimer timer; | |
137 BaselineScanner scanner(fname, isolate, encoding, &timer, repeat); | 135 BaselineScanner scanner(fname, isolate, encoding, &timer, repeat); |
138 Token::Value token; | 136 Token::Value token; |
139 int beg, end; | 137 int beg, end; |
140 do { | 138 do { |
141 token = scanner.Next(&beg, &end); | 139 token = scanner.Next(&beg, &end); |
142 if (dump_tokens) { | 140 if (dump_tokens) { |
143 tokens->push_back(TokenWithLocation(token, beg, end)); | 141 tokens->push_back(TokenWithLocation(token, beg, end)); |
144 } | 142 } |
145 } while (token != Token::EOS); | 143 } while (token != Token::EOS); |
146 return timer.Elapsed(); | 144 return timer.Elapsed(); |
147 } | 145 } |
148 | 146 |
149 | 147 |
150 void PrintTokens(const char* name, | 148 void PrintTokens(const char* name, |
151 const std::vector<TokenWithLocation>& tokens) { | 149 const std::vector<TokenWithLocation>& tokens) { |
152 printf("No of tokens: %d\n", | 150 printf("No of tokens: %d\n", |
153 static_cast<int>(tokens.size())); | 151 static_cast<int>(tokens.size())); |
154 printf("%s:\n", name); | 152 printf("%s:\n", name); |
155 for (size_t i = 0; i < tokens.size(); ++i) { | 153 for (size_t i = 0; i < tokens.size(); ++i) { |
156 tokens[i].Print("=>"); | 154 tokens[i].Print("=>"); |
157 } | 155 } |
158 } | 156 } |
159 | 157 |
160 | 158 |
161 TimeDelta ProcessFile( | 159 v8::base::TimeDelta ProcessFile( |
162 const char* fname, | 160 const char* fname, |
163 Encoding encoding, | 161 Encoding encoding, |
164 Isolate* isolate, | 162 Isolate* isolate, |
165 bool print_tokens, | 163 bool print_tokens, |
166 int repeat) { | 164 int repeat) { |
167 if (print_tokens) { | 165 if (print_tokens) { |
168 printf("Processing file %s\n", fname); | 166 printf("Processing file %s\n", fname); |
169 } | 167 } |
170 HandleScope handle_scope(isolate); | 168 HandleScope handle_scope(isolate); |
171 std::vector<TokenWithLocation> baseline_tokens; | 169 std::vector<TokenWithLocation> baseline_tokens; |
172 TimeDelta baseline_time; | 170 v8::base::TimeDelta baseline_time; |
173 baseline_time = RunBaselineScanner( | 171 baseline_time = RunBaselineScanner( |
174 fname, isolate, encoding, print_tokens, | 172 fname, isolate, encoding, print_tokens, |
175 &baseline_tokens, repeat); | 173 &baseline_tokens, repeat); |
176 if (print_tokens) { | 174 if (print_tokens) { |
177 PrintTokens("Baseline", baseline_tokens); | 175 PrintTokens("Baseline", baseline_tokens); |
178 } | 176 } |
179 return baseline_time; | 177 return baseline_time; |
180 } | 178 } |
181 | 179 |
182 | 180 |
(...skipping 27 matching lines...) Expand all Loading... |
210 { | 208 { |
211 v8::Isolate::Scope isolate_scope(isolate); | 209 v8::Isolate::Scope isolate_scope(isolate); |
212 v8::HandleScope handle_scope(isolate); | 210 v8::HandleScope handle_scope(isolate); |
213 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); | 211 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); |
214 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | 212 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
215 ASSERT(!context.IsEmpty()); | 213 ASSERT(!context.IsEmpty()); |
216 { | 214 { |
217 v8::Context::Scope scope(context); | 215 v8::Context::Scope scope(context); |
218 double baseline_total = 0; | 216 double baseline_total = 0; |
219 for (size_t i = 0; i < fnames.size(); i++) { | 217 for (size_t i = 0; i < fnames.size(); i++) { |
220 TimeDelta time; | 218 v8::base::TimeDelta time; |
221 time = ProcessFile(fnames[i].c_str(), encoding, | 219 time = ProcessFile(fnames[i].c_str(), encoding, |
222 reinterpret_cast<Isolate*>(isolate), print_tokens, | 220 reinterpret_cast<Isolate*>(isolate), print_tokens, |
223 repeat); | 221 repeat); |
224 baseline_total += time.InMillisecondsF(); | 222 baseline_total += time.InMillisecondsF(); |
225 } | 223 } |
226 if (benchmark.empty()) benchmark = "Baseline"; | 224 if (benchmark.empty()) benchmark = "Baseline"; |
227 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), baseline_total); | 225 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), baseline_total); |
228 } | 226 } |
229 } | 227 } |
230 v8::V8::Dispose(); | 228 v8::V8::Dispose(); |
231 return 0; | 229 return 0; |
232 } | 230 } |
OLD | NEW |