1
0

compose.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright © 2014 Ran Benita <ran234@gmail.com>
  3. * SPDX-License-Identifier: MIT
  4. */
  5. #include "config.h"
  6. #include <time.h>
  7. #include "xkbcommon/xkbcommon-compose.h"
  8. #include "../test/test.h"
  9. #include "bench.h"
  10. #define BENCHMARK_ITERATIONS 1000
  11. int
  12. main(void)
  13. {
  14. struct xkb_context *ctx;
  15. char *path;
  16. FILE *file;
  17. struct xkb_compose_table *table;
  18. struct bench bench;
  19. char *elapsed;
  20. ctx = test_get_context(CONTEXT_NO_FLAG);
  21. assert(ctx);
  22. path = test_get_path("locale/en_US.UTF-8/Compose");
  23. file = fopen(path, "rb");
  24. if (file == NULL) {
  25. perror(path);
  26. free(path);
  27. xkb_context_unref(ctx);
  28. return -1;
  29. }
  30. xkb_enable_quiet_logging(ctx);
  31. bench_start(&bench);
  32. for (int i = 0; i < BENCHMARK_ITERATIONS; i++) {
  33. fseek(file, 0, SEEK_SET);
  34. table = xkb_compose_table_new_from_file(ctx, file, "",
  35. XKB_COMPOSE_FORMAT_TEXT_V1,
  36. XKB_COMPOSE_COMPILE_NO_FLAGS);
  37. assert(table);
  38. xkb_compose_table_unref(table);
  39. }
  40. bench_stop(&bench);
  41. fclose(file);
  42. free(path);
  43. elapsed = bench_elapsed_str(&bench);
  44. fprintf(stderr, "compiled %d compose tables in %ss\n",
  45. BENCHMARK_ITERATIONS, elapsed);
  46. free(elapsed);
  47. xkb_context_unref(ctx);
  48. return 0;
  49. }