MCPcopy
hub / github.com/google/brotli / main

Method main

java/org/brotli/integration/Benchmark.java:49–116  ·  view source on GitHub ↗
(String... args)

Source from the content-addressed store, hash-verified

47 }
48
49 public static void main(String... args) throws IOException {
50 if (args.length == 0) {
51 System.out.println("Usage: benchmark <corpus>");
52 return;
53 }
54 File corpusDir = new File(args[0]);
55 ArrayList<String> fileNames = new ArrayList<String>();
56 File[] filesList = corpusDir.listFiles();
57 if (filesList == null) {
58 System.out.println("'" + args[0] + "' is not a directory");
59 return;
60 }
61 for (File file : filesList) {
62 if (!file.isFile()) {
63 continue;
64 }
65 String fileName = file.getAbsolutePath();
66 if (!fileName.endsWith(".brotli")) {
67 continue;
68 }
69 fileNames.add(fileName);
70 }
71 int fileCount = fileNames.size();
72 if (fileCount == 0) {
73 System.out.println("No files found");
74 return;
75 }
76 byte[][] files = new byte[fileCount][];
77 for (int i = 0; i < fileCount; ++i) {
78 files[i] = readFile(fileNames.get(i));
79 }
80
81 ByteArrayOutputStream baos = new ByteArrayOutputStream(65536);
82 byte[] buffer = new byte[65536];
83
84 int warmupRepeat = 10;
85 long bytesDecoded = 0;
86 for (int i = 0; i < warmupRepeat; ++i) {
87 bytesDecoded = 0;
88 for (int j = 0; j < fileCount; ++j) {
89 baos.reset();
90 bytesDecoded += decodeBytes(new ByteArrayInputStream(files[j]), baos, buffer);
91 }
92 }
93
94 int repeat = 100;
95
96 long bestTime = Long.MAX_VALUE;
97 for (int i = 0; i < repeat; ++i) {
98 long start = System.nanoTime();
99 for (int j = 0; j < fileCount; ++j) {
100 baos.reset();
101 decodeBytes(new ByteArrayInputStream(files[j]), baos, buffer);
102 }
103 long end = System.nanoTime();
104 long timeDelta = end - start;
105 if (timeDelta < bestTime) {
106 bestTime = timeDelta;

Callers

nothing calls this directly

Calls 3

readFileMethod · 0.95
decodeBytesMethod · 0.95
addMethod · 0.80

Tested by

no test coverage detected