forked from ChengFu-Ji/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeedup_performance.c
More file actions
39 lines (30 loc) · 889 Bytes
/
speedup_performance.c
File metadata and controls
39 lines (30 loc) · 889 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
#include <Python.h>
int slow_calc(int x, int a, int b)
{
return a * x + b;
}
static PyObject *_slow_calc(PyObject *self, PyObject *args, PyObject *kwargs)
{
int x, a = 0, b = 0;
int result = 0;
static char *kwlist[] = {"x", "a", "b", NULL};
if(!PyArg_ParseTupleAndKeywords(args, kwargs, "i|ii", kwlist, &x, &a, &b))
return NULL;
result = slow_calc(x, a, b);
return Py_BuildValue("i", result);
}
static PyMethodDef SpeedupPerformanceMethods[] = {
{"slow_calc", (PyCFunction) _slow_calc, METH_VARARGS | METH_KEYWORDS, NULL},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef speedup_performance_module = {
PyModuleDef_HEAD_INIT,
"speedup_performance",
NULL,
-1,
SpeedupPerformanceMethods
};
PyMODINIT_FUNC PyInit_speedup_performance()
{
return PyModule_Create(&speedup_performance_module);
}