File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1212
1313#include <unistd.h>
1414
15- /// Returns the number of instructions the process has executed since it was
16- /// launched.
15+ /// On macOS returns the number of instructions the process has executed since
16+ /// it was launched, on all other platforms returns 0 .
1717uint64_t getInstructionsExecuted ();
Original file line number Diff line number Diff line change 1010//
1111//===----------------------------------------------------------------------===//
1212
13+ #if __APPLE__
14+ #include <TargetConditionals.h>
15+ #if TARGET_OS_MAC && !TARGET_OS_IPHONE
16+ #define TARGET_IS_MACOS 1
17+ #endif
18+ #endif
19+
1320#include "InstructionsExecuted.h"
21+
22+ #ifdef TARGET_IS_MACOS
1423#include <libproc.h>
1524#include <sys/resource.h>
1625
@@ -21,3 +30,8 @@ uint64_t getInstructionsExecuted() {
2130 }
2231 return 0 ;
2332}
33+ #else
34+ uint64_t getInstructionsExecuted () {
35+ return 0 ;
36+ }
37+ #endif
Original file line number Diff line number Diff line change @@ -190,7 +190,11 @@ class PerformanceTest: ParsableCommand {
190190 let endDate = Date ( )
191191
192192 print ( " Time: \( endDate. timeIntervalSince ( start) / Double( self . iterations) * 1000 ) ms " )
193- print ( " Instructions: \( Double ( endInstructions - startInstructions) / Double( self . iterations) ) " )
193+ if endInstructions != startInstructions {
194+ // endInstructions == startInstructions only happens if we are on non-macOS
195+ // platforms that don't support `getInstructionsExecuted`. Don't display anything.
196+ print ( " Instructions: \( Double ( endInstructions - startInstructions) / Double( self . iterations) ) " )
197+ }
194198 }
195199}
196200
You can’t perform that action at this time.
0 commit comments