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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 StringResource8(const char* data, int length) | 49 StringResource8(const char* data, int length) |
50 : data_(data), length_(length) { } | 50 : data_(data), length_(length) { } |
51 virtual size_t length() const { return length_; } | 51 virtual size_t length() const { return length_; } |
52 virtual const char* data() const { return data_; } | 52 virtual const char* data() const { return data_; } |
53 | 53 |
54 private: | 54 private: |
55 const char* data_; | 55 const char* data_; |
56 int length_; | 56 int length_; |
57 }; | 57 }; |
58 | 58 |
59 std::pair<TimeDelta, TimeDelta> RunBaselineParser( | 59 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser( |
60 const char* fname, Encoding encoding, int repeat, v8::Isolate* isolate, | 60 const char* fname, Encoding encoding, int repeat, v8::Isolate* isolate, |
61 v8::Handle<v8::Context> context) { | 61 v8::Handle<v8::Context> context) { |
62 int length = 0; | 62 int length = 0; |
63 const byte* source = ReadFileAndRepeat(fname, &length, repeat); | 63 const byte* source = ReadFileAndRepeat(fname, &length, repeat); |
64 v8::Handle<v8::String> source_handle; | 64 v8::Handle<v8::String> source_handle; |
65 switch (encoding) { | 65 switch (encoding) { |
66 case UTF8: { | 66 case UTF8: { |
67 source_handle = v8::String::NewFromUtf8( | 67 source_handle = v8::String::NewFromUtf8( |
68 isolate, reinterpret_cast<const char*>(source)); | 68 isolate, reinterpret_cast<const char*>(source)); |
69 break; | 69 break; |
70 } | 70 } |
71 case UTF16: { | 71 case UTF16: { |
72 source_handle = v8::String::NewFromTwoByte( | 72 source_handle = v8::String::NewFromTwoByte( |
73 isolate, reinterpret_cast<const uint16_t*>(source), | 73 isolate, reinterpret_cast<const uint16_t*>(source), |
74 v8::String::kNormalString, length / 2); | 74 v8::String::kNormalString, length / 2); |
75 break; | 75 break; |
76 } | 76 } |
77 case LATIN1: { | 77 case LATIN1: { |
78 StringResource8* string_resource = | 78 StringResource8* string_resource = |
79 new StringResource8(reinterpret_cast<const char*>(source), length); | 79 new StringResource8(reinterpret_cast<const char*>(source), length); |
80 source_handle = v8::String::NewExternal(isolate, string_resource); | 80 source_handle = v8::String::NewExternal(isolate, string_resource); |
81 break; | 81 break; |
82 } | 82 } |
83 } | 83 } |
84 TimeDelta parse_time1, parse_time2; | 84 v8::base::TimeDelta parse_time1, parse_time2; |
85 Handle<Script> script = Isolate::Current()->factory()->NewScript( | 85 Handle<Script> script = Isolate::Current()->factory()->NewScript( |
86 v8::Utils::OpenHandle(*source_handle)); | 86 v8::Utils::OpenHandle(*source_handle)); |
87 i::ScriptData* cached_data_impl = NULL; | 87 i::ScriptData* cached_data_impl = NULL; |
88 // First round of parsing (produce data to cache). | 88 // First round of parsing (produce data to cache). |
89 { | 89 { |
90 CompilationInfoWithZone info(script); | 90 CompilationInfoWithZone info(script); |
91 info.MarkAsGlobal(); | 91 info.MarkAsGlobal(); |
92 info.SetCachedData(&cached_data_impl, i::PRODUCE_CACHED_DATA); | 92 info.SetCachedData(&cached_data_impl, i::PRODUCE_CACHED_DATA); |
93 ElapsedTimer timer; | 93 v8::base::ElapsedTimer timer; |
94 timer.Start(); | 94 timer.Start(); |
95 // Allow lazy parsing; otherwise we won't produce cached data. | 95 // Allow lazy parsing; otherwise we won't produce cached data. |
96 bool success = Parser::Parse(&info, true); | 96 bool success = Parser::Parse(&info, true); |
97 parse_time1 = timer.Elapsed(); | 97 parse_time1 = timer.Elapsed(); |
98 if (!success) { | 98 if (!success) { |
99 fprintf(stderr, "Parsing failed\n"); | 99 fprintf(stderr, "Parsing failed\n"); |
100 return std::make_pair(TimeDelta(), TimeDelta()); | 100 return std::make_pair(v8::base::TimeDelta(), v8::base::TimeDelta()); |
101 } | 101 } |
102 } | 102 } |
103 // Second round of parsing (consume cached data). | 103 // Second round of parsing (consume cached data). |
104 { | 104 { |
105 CompilationInfoWithZone info(script); | 105 CompilationInfoWithZone info(script); |
106 info.MarkAsGlobal(); | 106 info.MarkAsGlobal(); |
107 info.SetCachedData(&cached_data_impl, i::CONSUME_CACHED_DATA); | 107 info.SetCachedData(&cached_data_impl, i::CONSUME_CACHED_DATA); |
108 ElapsedTimer timer; | 108 v8::base::ElapsedTimer timer; |
109 timer.Start(); | 109 timer.Start(); |
110 // Allow lazy parsing; otherwise cached data won't help. | 110 // Allow lazy parsing; otherwise cached data won't help. |
111 bool success = Parser::Parse(&info, true); | 111 bool success = Parser::Parse(&info, true); |
112 parse_time2 = timer.Elapsed(); | 112 parse_time2 = timer.Elapsed(); |
113 if (!success) { | 113 if (!success) { |
114 fprintf(stderr, "Parsing failed\n"); | 114 fprintf(stderr, "Parsing failed\n"); |
115 return std::make_pair(TimeDelta(), TimeDelta()); | 115 return std::make_pair(v8::base::TimeDelta(), v8::base::TimeDelta()); |
116 } | 116 } |
117 } | 117 } |
118 return std::make_pair(parse_time1, parse_time2); | 118 return std::make_pair(parse_time1, parse_time2); |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 int main(int argc, char* argv[]) { | 122 int main(int argc, char* argv[]) { |
123 v8::V8::InitializeICU(); | 123 v8::V8::InitializeICU(); |
124 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 124 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
125 Encoding encoding = LATIN1; | 125 Encoding encoding = LATIN1; |
(...skipping 21 matching lines...) Expand all Loading... |
147 v8::Isolate::Scope isolate_scope(isolate); | 147 v8::Isolate::Scope isolate_scope(isolate); |
148 v8::HandleScope handle_scope(isolate); | 148 v8::HandleScope handle_scope(isolate); |
149 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); | 149 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); |
150 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | 150 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
151 ASSERT(!context.IsEmpty()); | 151 ASSERT(!context.IsEmpty()); |
152 { | 152 { |
153 v8::Context::Scope scope(context); | 153 v8::Context::Scope scope(context); |
154 double first_parse_total = 0; | 154 double first_parse_total = 0; |
155 double second_parse_total = 0; | 155 double second_parse_total = 0; |
156 for (size_t i = 0; i < fnames.size(); i++) { | 156 for (size_t i = 0; i < fnames.size(); i++) { |
157 std::pair<TimeDelta, TimeDelta> time = RunBaselineParser( | 157 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time = |
158 fnames[i].c_str(), encoding, repeat, isolate, context); | 158 RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate, |
| 159 context); |
159 first_parse_total += time.first.InMillisecondsF(); | 160 first_parse_total += time.first.InMillisecondsF(); |
160 second_parse_total += time.second.InMillisecondsF(); | 161 second_parse_total += time.second.InMillisecondsF(); |
161 } | 162 } |
162 if (benchmark.empty()) benchmark = "Baseline"; | 163 if (benchmark.empty()) benchmark = "Baseline"; |
163 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), | 164 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), |
164 first_parse_total); | 165 first_parse_total); |
165 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), | 166 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), |
166 second_parse_total); | 167 second_parse_total); |
167 } | 168 } |
168 } | 169 } |
169 v8::V8::Dispose(); | 170 v8::V8::Dispose(); |
170 return 0; | 171 return 0; |
171 } | 172 } |
OLD | NEW |