Commit d08aff31 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add small version of pidigits ubenchmark and fix gc issue

parent 2d19b2c1
......@@ -35,6 +35,14 @@ BoxedClass* long_cls;
#define IS_LITTLE_ENDIAN (int)*(unsigned char*)&one
#define PY_ABS_LLONG_MIN (0 - (unsigned PY_LONG_LONG)PY_LLONG_MIN)
void BoxedLong::gchandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b);
BoxedLong* l = (BoxedLong*)b;
v->visitPotentialRange((void**)&l->n, (void**)((&l->n) + 1));
}
extern "C" int _PyLong_Sign(PyObject* l) noexcept {
return mpz_sgn(static_cast<BoxedLong*>(l)->n);
}
......
......@@ -32,6 +32,8 @@ public:
BoxedLong() __attribute__((visibility("default"))) {}
static void gchandler(GCVisitor* v, Box* b);
DEFAULT_CLASS(long_cls);
};
......
......@@ -1024,7 +1024,7 @@ void setupRuntime() {
bool_cls = new BoxedHeapClass(int_cls, NULL, 0, sizeof(BoxedBool), false);
complex_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedComplex), false);
// TODO we're leaking long memory!
long_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedLong), false);
long_cls = new BoxedHeapClass(object_cls, &BoxedLong::gchandler, 0, sizeof(BoxedLong), false);
float_cls = new BoxedHeapClass(object_cls, NULL, 0, sizeof(BoxedFloat), false);
function_cls = new BoxedHeapClass(object_cls, &functionGCHandler, offsetof(BoxedFunction, attrs),
sizeof(BoxedFunction), false);
......
import time
def pidigits(length):
i = k = ns = 0
k1 = 1
n,a,d,t,u = 1,0,1,0,0
while(True):
k += 1
t = n<<1
n *= k
a += t
k1 += 2
a *= k1
d *= k1
if a >= n:
t,u = divmod(n*3 + a,d)
u += n
if d > u:
ns = ns*10 + t
i += 1
if i % 10 == 0:
print i, ns
ns = 0
if i >= length:
break
a -= d*t
a *= 10
n *= 10
pidigits(1000)
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