"Fossies" - the Fresh Open Source Software Archive

Member "utf8proc-2.4.0/bench/unistring.c" (11 May 2019, 1250 Bytes) of package /linux/privat/utf8proc-2.4.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "unistring.c" see the Fossies "Dox" file reference documentation.

    1 /* comparitive benchmark of GNU libunistring */
    2 
    3 #include <stdio.h>
    4 #include <stdlib.h>
    5 #include <string.h>
    6 
    7 /* libunistring */
    8 #include <unistr.h>
    9 #include <uninorm.h>
   10 
   11 #include "util.h"
   12 
   13 int main(int argc, char **argv)
   14 {
   15      int i;
   16      uninorm_t nf = UNINORM_NFKC;
   17 
   18      for (i = 1; i < argc; ++i) {
   19           if (!strcmp(argv[i], "-nfkc")) {
   20                nf = UNINORM_NFKC;
   21                continue;
   22           }
   23           if (!strcmp(argv[i], "-nfkd")) {
   24                nf = UNINORM_NFKD;
   25                continue;
   26           }
   27           if (!strcmp(argv[i], "-nfc")) {
   28                nf = UNINORM_NFC;
   29                continue;
   30           }
   31           if (!strcmp(argv[i], "-nfd")) {
   32                nf = UNINORM_NFD;
   33                continue;
   34           }
   35           if (argv[i][0] == '-') {
   36                fprintf(stderr, "unrecognized option: %s\n", argv[i]);
   37                return EXIT_FAILURE;
   38           }
   39 
   40           size_t len;
   41           uint8_t *src = readfile(argv[i], &len);
   42           if (!src) {
   43                fprintf(stderr, "error reading %s\n", argv[i]);
   44                return EXIT_FAILURE;
   45           }
   46 
   47           size_t destlen;
   48           uint8_t *dest;
   49           mytime start = gettime();
   50           for (int i = 0; i < 100; ++i) {
   51                dest = u8_normalize(nf, src, len, NULL, &destlen);
   52                if (!dest) return EXIT_FAILURE;
   53                free(dest);
   54           }
   55           printf("%s: %g\n", argv[i], elapsed(gettime(), start) / 100);
   56           free(src);
   57      }
   58 
   59      return EXIT_SUCCESS;
   60 }