Commit 05e14eb3 authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Some exception benchmarks and tests

parent aac0d9e6
def f():
# Try to eliminate as much non-exception stuff as possible:
from __builtin__ import Exception
e = Exception()
for i in xrange(100000):
try:
raise e
except Exception:
pass
f()
#include <vector>
#include <cstdio>
#include "stdint.h"
struct ExcInfo {
int64_t a, b, c;
};
void bench0() {
int64_t t = 0;
for (int i = 0; i < 1000000; i++) {
try {
throw 0;
} catch (int x) {
}
}
printf("%ld\n", t);
}
void bench1() {
int64_t t = 1;
for (int i = 0; i < 1000000; i++) {
try {
throw ExcInfo({.a=t, .b=t, .c=t});
} catch (ExcInfo e) {
t += e.a + e.b + e.c;
}
}
printf("b1 %ld\n", t);
}
static __thread ExcInfo curexc;
struct ExceptionOccurred {
};
void bench2() {
int64_t t = 1;
for (int i = 0; i < 1000000; i++) {
try {
curexc.a = t;
curexc.b = t;
curexc.c = t;
throw ExceptionOccurred();
} catch (ExceptionOccurred) {
t += curexc.a + curexc.b + curexc.c;
}
}
printf("b2 %ld\n", t);
}
void rbench1() {
int64_t t = 1;
for (int i = 0; i < 1000000; i++) {
try {
try {
throw ExcInfo({.a=t, .b=t, .c=t});
} catch (ExcInfo e) {
throw e;
}
} catch (ExcInfo e) {
t += e.a + e.b + e.c;
}
}
printf("rb1 %ld\n", t);
}
void rbench2() {
int64_t t = 1;
for (int i = 0; i < 1000000; i++) {
try {
try {
curexc.a = t;
curexc.b = t;
curexc.c = t;
throw ExceptionOccurred();
} catch (ExceptionOccurred x) {
throw x;
}
} catch (ExceptionOccurred) {
t += curexc.a + curexc.b + curexc.c;
}
}
printf("rb2 %ld\n", t);
}
int main() {
bench1();
}
......@@ -216,3 +216,33 @@ def f12():
print "after next:", sys.exc_info()[0]
list(i)
f12()
# If an exception is thrown+caught in course of exception-matching, we need to still operate on the original exception:
def f13():
print
print "f13"
def inner():
try:
raise KeyError
except:
pass
print sys.exc_info()[0]
return ZeroDivisionError
# This applies to what goes into exc_info:
try:
1/0
except inner():
print sys.exc_info()[0]
# This also applies to the exception that will propagate:
try:
try:
raise AttributeError()
except inner():
print "shouldn't get here!"
except Exception, e:
print type(e)
print sys.exc_info()[0]
f13()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment