benchmark.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_APACHE_LICENSE_HEADER_START@
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @APPLE_APACHE_LICENSE_HEADER_END@
  19. */
  20. /*
  21. * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
  22. * which are subject to change in future releases of Mac OS X. Any applications
  23. * relying on these interfaces WILL break.
  24. */
  25. #ifndef __DISPATCH_BENCHMARK__
  26. #define __DISPATCH_BENCHMARK__
  27. #ifndef __DISPATCH_INDIRECT__
  28. #error "Please #include <dispatch/private.h> instead of this file directly."
  29. #include <dispatch/base.h> // for HeaderDoc
  30. #endif
  31. DISPATCH_ASSUME_NONNULL_BEGIN
  32. __BEGIN_DECLS
  33. /*!
  34. * @function dispatch_benchmark
  35. *
  36. * @abstract
  37. * Count the average number of cycles a given block takes to execute.
  38. *
  39. * @param count
  40. * The number of times to serially execute the given block.
  41. *
  42. * @param block
  43. * The block to execute.
  44. *
  45. * @result
  46. * The approximate number of cycles the block takes to execute.
  47. *
  48. * @discussion
  49. * This function is for debugging and performance analysis work. For the best
  50. * results, pass a high count value to dispatch_benchmark(). When benchmarking
  51. * concurrent code, please compare the serial version of the code against the
  52. * concurrent version, and compare the concurrent version on different classes
  53. * of hardware. Please look for inflection points with various data sets and
  54. * keep the following facts in mind:
  55. *
  56. * 1) Code bound by computational bandwidth may be inferred by proportional
  57. * changes in performance as concurrency is increased.
  58. * 2) Code bound by memory bandwidth may be inferred by negligible changes in
  59. * performance as concurrency is increased.
  60. * 3) Code bound by critical sections may be inferred by retrograde changes in
  61. * performance as concurrency is increased.
  62. * 3a) Intentional: locks, mutexes, and condition variables.
  63. * 3b) Accidental: unrelated and frequently modified data on the same
  64. * cache-line.
  65. */
  66. #ifdef __BLOCKS__
  67. API_AVAILABLE(macos(10.6), ios(4.0))
  68. DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NOTHROW
  69. uint64_t
  70. dispatch_benchmark(size_t count, dispatch_block_t block);
  71. #endif
  72. API_AVAILABLE(macos(10.6), ios(4.0))
  73. DISPATCH_EXPORT DISPATCH_NONNULL3 DISPATCH_NOTHROW
  74. uint64_t
  75. dispatch_benchmark_f(size_t count, void *_Nullable ctxt,
  76. dispatch_function_t func);
  77. __END_DECLS
  78. DISPATCH_ASSUME_NONNULL_END
  79. #endif