2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #define LOG_TAG "DLOG_BENCHMARK"
25 int main (int argc, char **argv)
27 if (argc != 4 && argc != 5) {
28 fprintf(stderr, "argc = %d\n", argc);
32 bool buffered = atoi(argv[1]) != 0;
33 setvbuf(stdout, NULL, buffered ? _IOLBF : _IONBF, 0);
35 int const N = atoi(argv[2]);
36 char const *MSG = argv[3];
37 char const *where = argc == 4 ? "" : argv[4];
39 struct timespec start, end;
40 inline void print_diff (char const *name) {
41 double elapsed_s = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1E9;
42 fprintf(stderr, "%s: %lfus per log (%lfs total per %d logs)\n"
44 , 1000000 * elapsed_s / N
50 if (strcmp(where, "stdout") == 0 || strcmp(where, "") == 0) {
51 for (int i = 0; i < 10000; ++i)
52 printf("stdout warm-up\n");
54 clock_gettime(CLOCK_MONOTONIC, &start);
55 for (int i = 0; i < N; ++i)
57 clock_gettime(CLOCK_MONOTONIC, &end);
58 print_diff(buffered ? "stdout (buffered)" : "stdout (not buffered)");
61 if (strcmp(where, "libdlog") == 0 || strcmp(where, "") == 0) {
62 for (int i = 0; i < 10000; ++i)
63 LOGE("libdlog warm-up\n");
65 clock_gettime(CLOCK_MONOTONIC, &start);
66 for (int i = 0; i < N; ++i)
68 clock_gettime(CLOCK_MONOTONIC, &end);
69 print_diff("libdlog");