GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 115c41f4 authored by John Zhang's avatar John Zhang

wip: refactor performance comparison code. Need floating point support to embed…

wip: refactor performance comparison code. Need floating point support to embed time measurement code in RPython side
parent 592b797b
Pipeline #174 passed with stage
in 19 minutes and 5 seconds
This diff is collapsed.
#include <stdint.h>
uint64_t arraysum(int64_t* arr, uint64_t sz) {
int64_t sum = 0;
uint64_t i;
for(i = 0; i < sz; i ++) {
sum += arr[i];
return sum;
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib.jit import JitDriver
d = JitDriver(greens=[], reds='auto')
def arraysum(arr, sz):
sum = rffi.r_longlong(0)
for i in range(sz):
sum += arr[i]
return sum
def setup(n):
lst, _ = rand_list_of(n)
arr = lltype.malloc(rffi.CArray(rffi.LONGLONG), n, flavor='raw')
for i, k in enumerate(lst):
arr[i] = k
return rffi.ll2ctypes.lltype2ctypes(arr) , n
def teardown(carr, n):, carr), 'raw')
def rand_list_of(n):
# 32 extend to 64-bit integers (to avoid overflow in summation
from random import randrange, getstate
init_state = getstate()
return [rffi.r_longlong(randrange(-(1 << 31), (1 << 31) - 1)) for _ in range(n)], init_state
def measure(N):
args = setup(N)
from time import time
t0 = time()
t1 = time()
return t0, t1
def rpy_entry(N):
t0, t1 = measure(N)
# from rpython.rlib import rfloat
# print rfloat.double_to_string(t1 - t0, 'e', %(fprec)d, rfloat.DTSF_ADD_DOT_0)
return t1 - t0
if __name__ == '__main__':
import sys
t0, t1 = measure(int(sys.argv[1]))
print '%.15f' % (t1 - t0)
def target(*args):
from rpython.rlib.entrypoint import export_symbol
return rpy_entry, [int]
\ No newline at end of file
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