-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry_location.cpp
More file actions
57 lines (50 loc) · 998 Bytes
/
try_location.cpp
File metadata and controls
57 lines (50 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Timer.h"
#include <print>
#include <stdexcept>
constexpr int big = 50'000;
void __attribute__((__noinline__)) foo(int x, int y) {
if (x == big && y == big) {
throw std::runtime_error("Wow");
}
}
int main() {
{
Timer timer{"Outer"};
try {
for (int x = 0; x <= big; ++x) {
for (int y = 0; y <= big; ++y) {
foo(x, y);
}
}
} catch (const std::runtime_error &error) {
std::println("Caught outer: {}", error.what());
}
}
{
Timer timer{"Inner"};
for (int x = 0; x <= big; ++x) {
for (int y = 0; y <= big; ++y) {
try {
foo(x, y);
} catch (const std::runtime_error &error) {
std::println("Caught inner: {}", error.what());
break;
}
}
}
}
{
Timer timer{"Middle"};
for (int x = 0; x <= big; ++x) {
try {
for (int y = 0; y <= big; ++y) {
foo(x, y);
}
} catch (const std::runtime_error &error) {
std::println("Caught middle: {}", error.what());
break;
}
}
}
Timer::summary();
}