File: benchmark.cpp

package info (click to toggle)
libdivide 5.2.0-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,564 kB
  • sloc: ansic: 131,647; cpp: 70,136; python: 47; makefile: 3
file content (73 lines) | stat: -rw-r--r-- 2,728 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Usage: benchmark [OPTIONS]
//
// You can pass the benchmark program one or more of the following
// options: u32, s32, u64, s64 to compare libdivide's speed against
// hardware division. If benchmark is run without any options u64
// is used as default option. benchmark tests a simple function that
// inputs an array of random numerators and a single divisor, and
// returns the sum of their quotients. It tests this using both
// hardware division, and the various division approaches supported
// by libdivide, including vector division.

// Silence MSVC sprintf unsafe warnings
#define _CRT_SECURE_NO_WARNINGS

#include "benchmark.h"

#include <string.h>

extern "C" int main(int argc, char *argv[]) {
    // Disable printf buffering.
    // This is mainly required for Windows.
    setbuf(stdout, NULL);

    bool u16 = 0;
    bool s16 = 0;
    bool u32 = 0;
    bool s32 = 0;
    bool u64 = 0;
    bool s64 = 0;

    if (argc == 1) {
        // By default test only u64
        u64 = 1;
    } else {
        for (int i = 1; i < argc; i++) {
            if (!strcmp(argv[i], type_tag<uint16_t>::get_tag()))
                u16 = true;
            else if (!strcmp(argv[i], type_tag<uint32_t>::get_tag()))
                u32 = true;
            else if (!strcmp(argv[i], type_tag<uint64_t>::get_tag()))
                u64 = true;
            else if (!strcmp(argv[i], type_tag<int16_t>::get_tag()))
                s16 = true;
            else if (!strcmp(argv[i], type_tag<int32_t>::get_tag()))
                s32 = true;
            else if (!strcmp(argv[i], type_tag<int64_t>::get_tag()))
                s64 = true;
            else {
                printf(
                    "Usage: benchmark [OPTIONS]\n"
                    "\n"
                    "You can pass the benchmark program one or more of the following\n"
                    "options: u16, s16, u32, s32, u64, s64 to compare libdivide's speed against\n"
                    "hardware division. If benchmark is run without any options u64\n"
                    "is used as default option. benchmark tests a simple function that\n"
                    "inputs an array of random numerators and a single divisor, and\n"
                    "returns the sum of their quotients. It tests this using both\n"
                    "hardware division, and the various division approaches supported\n"
                    "by libdivide, including vector division.\n");
                exit(1);
            }
        }
    }

    if (u16) test_many<uint16_t>();
    if (s16) test_many<int16_t>();
    if (u32) test_many<uint32_t>();
    if (s32) test_many<int32_t>();
    if (u64) test_many<uint64_t>();
    if (s64) test_many<int64_t>();

    return 0;
}