gf_vect_mul_perf.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**********************************************************************
  2. Copyright(c) 2011-2015 Intel Corporation All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in
  10. the documentation and/or other materials provided with the
  11. distribution.
  12. * Neither the name of Intel Corporation nor the names of its
  13. contributors may be used to endorse or promote products derived
  14. from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. **********************************************************************/
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h> // for memset
  30. #include "erasure_code.h"
  31. #include "test.h"
  32. #ifndef GT_L3_CACHE
  33. # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
  34. #endif
  35. #if !defined(COLD_TEST) && !defined(TEST_CUSTOM)
  36. // Cached test, loop many times over small dataset
  37. # define TEST_SOURCES 10
  38. # define TEST_LEN 8*1024
  39. # define TEST_TYPE_STR "_warm"
  40. #elif defined (COLD_TEST)
  41. // Uncached test. Pull from large mem base.
  42. # define TEST_SOURCES 10
  43. # define TEST_LEN (GT_L3_CACHE / 2)
  44. # define TEST_TYPE_STR "_cold"
  45. #elif defined (TEST_CUSTOM)
  46. # define TEST_TYPE_STR "_cus"
  47. #endif
  48. #define TEST_MEM (2 * TEST_LEN)
  49. typedef unsigned char u8;
  50. void gf_vect_mul_perf(u8 a, u8 * gf_const_tbl, u8 * buff1, u8 * buff2)
  51. {
  52. gf_vect_mul_init(a, gf_const_tbl);
  53. gf_vect_mul(TEST_LEN, gf_const_tbl, buff1, buff2);
  54. }
  55. int main(int argc, char *argv[])
  56. {
  57. u8 *buff1, *buff2, gf_const_tbl[64], a = 2;
  58. struct perf start;
  59. printf("gf_vect_mul_perf:\n");
  60. // Allocate large mem region
  61. buff1 = (u8 *) malloc(TEST_LEN);
  62. buff2 = (u8 *) malloc(TEST_LEN);
  63. if (NULL == buff1 || NULL == buff2) {
  64. printf("Failed to allocate %dB\n", TEST_LEN);
  65. return 1;
  66. }
  67. memset(buff1, 0, TEST_LEN);
  68. memset(buff2, 0, TEST_LEN);
  69. printf("Start timed tests\n");
  70. fflush(0);
  71. BENCHMARK(&start, BENCHMARK_TIME, gf_vect_mul_perf(a, gf_const_tbl, buff1, buff2));
  72. printf("gf_vect_mul" TEST_TYPE_STR ": ");
  73. perf_print(start, (long long)TEST_LEN);
  74. return 0;
  75. }