Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions hwcounter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "Python.h"
#include "structmember.h"

#if PY_MAJOR_VERSION >= 3
#define PY3K
#endif

#define HWCOUNTER_GET_TIMESTAMP(count_ptr) \
do { \
uint32_t count_high, count_low; \
Expand Down Expand Up @@ -179,6 +183,8 @@ static PyMethodDef hwcounter_methods[] = {
{NULL, NULL, 0, NULL}
};

#ifdef PY3K
// module initialization for python3
static struct PyModuleDef hwcounter_module = {
PyModuleDef_HEAD_INIT,
"hwcounter",
Expand All @@ -204,3 +210,23 @@ PyInit_hwcounter(void)

return m;
}
#else
// module initialization for python2
PyMODINIT_FUNC
inithwcounter(void)
{
PyObject *m;

hwcounter_TimerType.tp_new = PyType_GenericNew;
if (PyType_Ready(&hwcounter_TimerType) < 0)
return NULL;

if ((m = Py_InitModule3("hwcounter", hwcounter_methods, "This module provides access to a very accurate, high-resolution hardware counter for measurement of time, in terms of processor clock cycles.")) == NULL)
return NULL;

Py_INCREF(&hwcounter_TimerType);
PyModule_AddObject(m, "Timer", (PyObject *)&hwcounter_TimerType);

return m;
}
#endif
13 changes: 10 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from setuptools import setup, Extension
from os import path
import sys

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
if sys.version_info[0] >= 3:
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
else:
with open(path.join(here, 'README.md')) as f:
long_description = f.read()

setup(name = 'hwcounter',
version = '0.1.0',
version = '0.1.2',
description = 'Highly accurate counter for measuring elapsed time in Python',
long_description = long_description,
url = 'https://github.com/paulsmith/hwcounter',
Expand All @@ -18,6 +23,8 @@
'Intended Audience :: Developers',
'Topic :: System :: Benchmark',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
Expand Down