Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite01e49f

Browse files
committed
Perf demo of zero cost exceptions.
1 parentf0f67fd commite01e49f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
importdatetime
2+
fromdisimportdis
3+
4+
5+
deftroubling_method(x:str)->int:
6+
# print(f"We will take a shot at converting {x}")
7+
8+
try:
9+
returnint(x)
10+
exceptValueErrorasve:
11+
print(f"Oh no, it couldn't be converted because of values:{ve}")
12+
exceptNotImplementedError:
13+
print("Somehow not implemented?")
14+
except:
15+
print("We have no idea")
16+
17+
# print("There was some kind of error")
18+
return-1
19+
20+
21+
defmain():
22+
troubling_method("77")
23+
24+
# print(troubling_method("77"))
25+
# print(troubling_method("901"))
26+
# # print(troubling_method(902))
27+
# print(troubling_method("Nine hundred"))
28+
#
29+
# dis(troubling_method)
30+
31+
times=10_000_000
32+
t0=datetime.datetime.now()
33+
34+
for_inrange(times):
35+
troubling_method("77")
36+
37+
t1=datetime.datetime.now()
38+
dt=t1-t0
39+
print(f"Done in{dt.total_seconds()*1000:,.2f} ms")
40+
41+
42+
if__name__=='__main__':
43+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp