Skip to content

Instantly share code, notes, and snippets.

View tistaharahap's full-sized avatar

Batista Harahap tistaharahap

View GitHub Profile
MariaDB [fun]> SELECT * FROM names;
+----+------------+------------+
| id | first_name | last_name |
+----+------------+------------+
| 1 | Batista | Harahap |
| 2 | Rinto | Harahap |
| 3 | Michael | Jordan |
| 4 | Chris | Martin |
| 5 | Jordan | Sparks |
| 6 | Daniel | Craig |
$ python cythondemo.py
Elapsed Time: 3.86 second
Ops/second: 25903031.00
from cpuload import load
import time
if __name__ == '__main__':
max = 100000000
_start = time.time()
load(10, max)
_end = time.time()
$ python setup.py build_ext --inplace
running build_ext
building 'cythondemo' extension
cc -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cythondemo.c -o build/temp.macosx-10.11-intel-2.7/cythondemo.o
cythondemo.c:2531:28: warning: unused function '__Pyx_PyObject_AsString'
[-Wunused-function]
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
^
cythondemo.c:2528:32: warning: unused function '__Pyx_PyUnicode_FromString'
[-Wunused-function]
from setuptools import setup, Extension
setup(ext_modules=[Extension("cpuload", ["cpuload.c"])],
name='cpuload',
version='0.0.1',
description='A simple Cython demo',
long_description='A simple Cython demo',
keywords='cython demo',
author='Batista Harahap',
$ pip install cython
$ cython cpuload.py
$ ls -la cpuload.*
...
-rw-r--r-- 1 tista staff 131178 Aug 28 18:58 cpuload.c
-rw-r--r-- 1 tista staff 76 Aug 28 18:58 cpuload.py
...
$ python cpuload.py
Elapsed Time: 7.68 second
Ops/second: 13018765.56
import time
def load(number, max):
for x in xrange(1, max):
number*number*x
if __name__ == '__main__':
max = 100000000
_start = time.time()
MariaDB [fun]> SELECT COUNT(DISTINCT last_name) AS cardinality FROM users;
+-------------+
| cardinality |
+-------------+
| 9 |
+-------------+
MariaDB [fun]> SELECT * FROM users;
+----+------------+------------+
| id | first_name | last_name |
+----+------------+------------+
| 1 | Batista | Harahap |
| 2 | Rinto | Harahap |
| 3 | Michael | Jordan |
| 4 | Chris | Martin |
| 5 | Jordan | Sparks |
| 6 | Daniel | Craig |