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

Side by Side Diff: third_party/ots/test/perf.cc

Issue 775893002: Updating OTS repo from https://github.com/khaledhosny/ots.git (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating with 4800 warning fix Created 6 years 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
« no previous file with comments | « third_party/ots/test/ot-sanitise.cc ('k') | third_party/ots/test/side-by-side.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <fcntl.h>
6 #include <sys/stat.h>
7 #include <sys/time.h>
8 #include <unistd.h>
9 #include <time.h>
10
11 #include <cstdio>
12 #include <cstdlib>
13 #include <cstring>
14
15 #include "opentype-sanitiser.h"
16 #include "ots-memory-stream.h"
17
18 namespace {
19
20 int Usage(const char *argv0) {
21 std::fprintf(stderr, "Usage: %s <ttf file>\n", argv0);
22 return 1;
23 }
24
25 } // namespace
26
27 int main(int argc, char **argv) {
28 if (argc != 2) return Usage(argv[0]);
29
30 const int fd = ::open(argv[1], O_RDONLY);
31 if (fd < 0) {
32 ::perror("open");
33 return 1;
34 }
35
36 struct stat st;
37 ::fstat(fd, &st);
38
39 uint8_t *data = new uint8_t[st.st_size];
40 if (::read(fd, data, st.st_size) != st.st_size) {
41 std::fprintf(stderr, "Failed to read file!\n");
42 return 1;
43 }
44
45 // A transcoded font is usually smaller than an original font.
46 // However, it can be slightly bigger than the original one due to
47 // name table replacement and/or padding for glyf table.
48 static const size_t kPadLen = 20 * 1024;
49 uint8_t *result = new uint8_t[st.st_size + kPadLen];
50
51 int num_repeat = 250;
52 if (st.st_size < 1024 * 1024) {
53 num_repeat = 2500;
54 }
55 if (st.st_size < 1024 * 100) {
56 num_repeat = 5000;
57 }
58
59 struct timeval start, end, elapsed;
60 ::gettimeofday(&start, 0);
61 for (int i = 0; i < num_repeat; ++i) {
62 ots::MemoryStream output(result, st.st_size + kPadLen);
63 ots::OTSContext context;
64 bool r = context.Process(&output, data, st.st_size);
65 if (!r) {
66 std::fprintf(stderr, "Failed to sanitise file!\n");
67 return 1;
68 }
69 }
70 ::gettimeofday(&end, 0);
71 timersub(&end, &start, &elapsed);
72
73 long long unsigned us
74 = ((elapsed.tv_sec * 1000 * 1000) + elapsed.tv_usec) / num_repeat;
75 std::fprintf(stderr, "%llu [us] %s (%llu bytes, %llu [byte/us])\n",
76 us, argv[1], static_cast<long long>(st.st_size),
77 (us ? st.st_size / us : 0));
78
79 return 0;
80 }
OLDNEW
« no previous file with comments | « third_party/ots/test/ot-sanitise.cc ('k') | third_party/ots/test/side-by-side.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698