Skip to content

Commit 024726f

Browse files
committed
[swift-parse-test] Dont show throughput if it the elasped time is zero
Fix division by zero. rdar://117750086
1 parent b0105e1 commit 024726f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/DriverTool/swift_parse_test_main.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ static std::pair<Duration, Duration> measure(llvm::function_ref<void()> body) {
141141
auto tEnd = std::chrono::steady_clock::now();
142142

143143
auto clockMultiply =
144-
Duration::period::den / CLOCKS_PER_SEC / Duration::period::num;
144+
CLOCKS_PER_SEC > 0
145+
? (Duration::period::den / CLOCKS_PER_SEC / Duration::period::num)
146+
: 0;
145147

146148
Duration cDuration((cEnd - cStart) * clockMultiply);
147149
return {std::chrono::duration_cast<Duration>(tEnd - tStart),
@@ -177,14 +179,16 @@ perform(const SmallVectorImpl<std::unique_ptr<llvm::MemoryBuffer>> &buffers,
177179
std::chrono::duration_cast<std::chrono::milliseconds>(tDuration).count();
178180
auto cDisplay =
179181
std::chrono::duration_cast<std::chrono::milliseconds>(cDuration).count();
182+
llvm::outs() << llvm::format("wall clock time (ms): %8d\n", tDisplay)
183+
<< llvm::format("cpu time (ms): %8d\n", cDisplay);
180184

181-
auto byteTPS = totalBytes * duration_t::period::den / cDuration.count();
182-
auto lineTPS = totalLines * duration_t::period::den / cDuration.count();
185+
if (cDuration.count() > 0) {
186+
auto byteTPS = totalBytes * duration_t::period::den / cDuration.count();
187+
auto lineTPS = totalLines * duration_t::period::den / cDuration.count();
183188

184-
llvm::outs() << llvm::format("wall clock time (ms): %8d\n", tDisplay)
185-
<< llvm::format("cpu time (ms): %8d\n", cDisplay)
186-
<< llvm::format("throughput (byte/s): %8d\n", byteTPS)
187-
<< llvm::format("throughput (line/s): %8d\n", lineTPS);
189+
llvm::outs() << llvm::format("throughput (byte/s): %8d\n", byteTPS)
190+
<< llvm::format("throughput (line/s): %8d\n", lineTPS);
191+
}
188192
}
189193

190194
} // namespace

test/Misc/parse_test.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// REQUIRES: swift_swift_parser
2-
// RUN: %swift-parse-test -swift-parser -lib-parse -skip-bodies -n 2 %s
3-
// REQUIRES: rdar117750086
2+
// RUN: %swift-parse-test -swift-parser -lib-parse -skip-bodies -n 10 %s
3+
44
struct S {
55
func foo() {
66
print(1)

0 commit comments

Comments
 (0)