| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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> | |
| 30 #include <string.h> | 29 #include <string.h> |
| 31 #include <stdio.h> | 30 #include <stdio.h> |
| 32 #include <stdlib.h> | 31 #include <stdlib.h> |
| 33 #include <string> | 32 #include <string> |
| 34 #include <vector> | 33 #include <vector> |
| 35 #include "v8.h" | 34 #include "v8.h" |
| 36 | 35 |
| 37 #include "api.h" | 36 #include "api.h" |
| 38 #include "ast.h" | |
| 39 #include "char-predicates-inl.h" | |
| 40 #include "messages.h" | 37 #include "messages.h" |
| 41 #include "platform.h" | 38 #include "platform.h" |
| 42 #include "runtime.h" | 39 #include "runtime.h" |
| 43 #include "scanner-character-streams.h" | 40 #include "scanner-character-streams.h" |
| 44 #include "scopeinfo.h" | 41 #include "scopeinfo.h" |
| 42 #include "shell-utils.h" |
| 45 #include "string-stream.h" | 43 #include "string-stream.h" |
| 46 #include "scanner.h" | 44 #include "scanner.h" |
| 47 | 45 |
| 48 | 46 |
| 49 using namespace v8::internal; | 47 using namespace v8::internal; |
| 50 | 48 |
| 51 enum Encoding { | |
| 52 LATIN1, | |
| 53 UTF8, | |
| 54 UTF16 | |
| 55 }; | |
| 56 | |
| 57 | |
| 58 const byte* ReadFile(const char* name, Isolate* isolate, | |
| 59 int* size, int repeat) { | |
| 60 FILE* file = fopen(name, "rb"); | |
| 61 *size = 0; | |
| 62 if (file == NULL) return NULL; | |
| 63 | |
| 64 fseek(file, 0, SEEK_END); | |
| 65 int file_size = ftell(file); | |
| 66 rewind(file); | |
| 67 | |
| 68 *size = file_size * repeat; | |
| 69 | |
| 70 byte* chars = new byte[*size + 1]; | |
| 71 for (int i = 0; i < file_size;) { | |
| 72 int read = static_cast<int>(fread(&chars[i], 1, file_size - i, file)); | |
| 73 i += read; | |
| 74 } | |
| 75 fclose(file); | |
| 76 | |
| 77 for (int i = file_size; i < *size; i++) { | |
| 78 chars[i] = chars[i - file_size]; | |
| 79 } | |
| 80 chars[*size] = 0; | |
| 81 | |
| 82 return chars; | |
| 83 } | |
| 84 | |
| 85 | 49 |
| 86 class BaselineScanner { | 50 class BaselineScanner { |
| 87 public: | 51 public: |
| 88 BaselineScanner(const char* fname, | 52 BaselineScanner(const char* fname, |
| 89 Isolate* isolate, | 53 Isolate* isolate, |
| 90 Encoding encoding, | 54 Encoding encoding, |
| 91 ElapsedTimer* timer, | 55 ElapsedTimer* timer, |
| 92 int repeat) | 56 int repeat) |
| 93 : stream_(NULL) { | 57 : stream_(NULL) { |
| 94 int length = 0; | 58 int length = 0; |
| 95 source_ = ReadFile(fname, isolate, &length, repeat); | 59 source_ = ReadFileAndRepeat(fname, &length, repeat); |
| 96 unicode_cache_ = new UnicodeCache(); | 60 unicode_cache_ = new UnicodeCache(); |
| 97 scanner_ = new Scanner(unicode_cache_); | 61 scanner_ = new Scanner(unicode_cache_); |
| 98 switch (encoding) { | 62 switch (encoding) { |
| 99 case UTF8: | 63 case UTF8: |
| 100 stream_ = new Utf8ToUtf16CharacterStream(source_, length); | 64 stream_ = new Utf8ToUtf16CharacterStream(source_, length); |
| 101 break; | 65 break; |
| 102 case UTF16: { | 66 case UTF16: { |
| 103 Handle<String> result = isolate->factory()->NewStringFromTwoByte( | 67 Handle<String> result = isolate->factory()->NewStringFromTwoByte( |
| 104 Vector<const uint16_t>( | 68 Vector<const uint16_t>( |
| 105 reinterpret_cast<const uint16_t*>(source_), | 69 reinterpret_cast<const uint16_t*>(source_), |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 repeat); | 222 repeat); |
| 259 baseline_total += time.InMillisecondsF(); | 223 baseline_total += time.InMillisecondsF(); |
| 260 } | 224 } |
| 261 if (benchmark.empty()) benchmark = "Baseline"; | 225 if (benchmark.empty()) benchmark = "Baseline"; |
| 262 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), baseline_total); | 226 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), baseline_total); |
| 263 } | 227 } |
| 264 } | 228 } |
| 265 v8::V8::Dispose(); | 229 v8::V8::Dispose(); |
| 266 return 0; | 230 return 0; |
| 267 } | 231 } |
| OLD | NEW |