You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

benchmark.cpp 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #ifdef _WIN32
  15. #define WIN32_LEAN_AND_MEAN
  16. #include <windows.h>
  17. #else // _WIN32
  18. #include <sys/time.h>
  19. #endif // _WIN32
  20. #include "benchmark.h"
  21. #if NCNN_BENCHMARK
  22. #include <stdio.h>
  23. #include "layer/convolution.h"
  24. #include "layer/convolutiondepthwise.h"
  25. #include "layer/deconvolution.h"
  26. #include "layer/deconvolutiondepthwise.h"
  27. #endif // NCNN_BENCHMARK
  28. namespace ncnn {
  29. #ifdef _WIN32
  30. double get_current_time()
  31. {
  32. LARGE_INTEGER freq;
  33. LARGE_INTEGER pc;
  34. QueryPerformanceFrequency(&freq);
  35. QueryPerformanceCounter(&pc);
  36. return pc.QuadPart * 1000.0 / freq.QuadPart;
  37. }
  38. #else // _WIN32
  39. double get_current_time()
  40. {
  41. struct timeval tv;
  42. gettimeofday(&tv, NULL);
  43. return tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
  44. }
  45. #endif // _WIN32
  46. #if NCNN_BENCHMARK
  47. void benchmark(const Layer* layer, double start, double end)
  48. {
  49. fprintf(stderr, "%-24s %-30s %8.2lfms", layer->type.c_str(), layer->name.c_str(), end - start);
  50. fprintf(stderr, " |");
  51. fprintf(stderr, "\n");
  52. }
  53. void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double start, double end)
  54. {
  55. fprintf(stderr, "%-24s %-30s %8.2lfms", layer->type.c_str(), layer->name.c_str(), end - start);
  56. fprintf(stderr, " | feature_map: %4d x %-4d inch: %4d outch: %4d", bottom_blob.w, bottom_blob.h, bottom_blob.c, top_blob.c);
  57. if (layer->type == "Convolution")
  58. {
  59. fprintf(stderr, " kernel: %1d x %1d stride: %1d x %1d",
  60. ((Convolution*)layer)->kernel_w,
  61. ((Convolution*)layer)->kernel_h,
  62. ((Convolution*)layer)->stride_w,
  63. ((Convolution*)layer)->stride_h
  64. );
  65. }
  66. else if (layer->type == "ConvolutionDepthWise")
  67. {
  68. fprintf(stderr, " kernel: %1d x %1d stride: %1d x %1d",
  69. ((ConvolutionDepthWise*)layer)->kernel_w,
  70. ((ConvolutionDepthWise*)layer)->kernel_h,
  71. ((ConvolutionDepthWise*)layer)->stride_w,
  72. ((ConvolutionDepthWise*)layer)->stride_h
  73. );
  74. }
  75. else if (layer->type == "Deconvolution")
  76. {
  77. fprintf(stderr, " kernel: %1d x %1d stride: %1d x %1d",
  78. ((Deconvolution*)layer)->kernel_w,
  79. ((Deconvolution*)layer)->kernel_h,
  80. ((Deconvolution*)layer)->stride_w,
  81. ((Deconvolution*)layer)->stride_h
  82. );
  83. }
  84. else if (layer->type == "DeconvolutionDepthWise")
  85. {
  86. fprintf(stderr, " kernel: %1d x %1d stride: %1d x %1d",
  87. ((DeconvolutionDepthWise*)layer)->kernel_w,
  88. ((DeconvolutionDepthWise*)layer)->kernel_h,
  89. ((DeconvolutionDepthWise*)layer)->stride_w,
  90. ((DeconvolutionDepthWise*)layer)->stride_h
  91. );
  92. }
  93. fprintf(stderr, "\n");
  94. }
  95. #endif // NCNN_BENCHMARK
  96. } // namespace ncnn