Last active
August 29, 2015 14:20
-
-
Save belltailjp/d40a214321471be4e329 to your computer and use it in GitHub Desktop.
Benchmark of enforcing 1st row/col to be smaller than the second.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from benchmarker import Benchmarker | |
N = 10 ** 8 | |
with Benchmarker(1000) as bench: | |
@bench('col-proposed') | |
def _(bm): | |
a = numpy.random.randint(0, 100, (2, N)) | |
with bm: | |
a[:, a[1] < a[0]] = a[:, a[1] < a[0]][::-1] | |
@bench('row-proposed') | |
def _(bm): | |
a = numpy.random.randint(0, 100, (N, 2)) | |
with bm: | |
a[a[:, 1] < a[:, 0]] = a[a[:, 1] < a[:, 0]][:, ::-1] | |
@bench('col-conventional') | |
def _(bm): | |
a = numpy.random.randint(0, 100, (2, N)) | |
with bm: | |
for j in range(a.shape[1]): | |
if a[1, j] < a[0, j]: | |
a[1, j], a[0, j] = a[0, j], a[1, j] | |
@bench('row-conventional') | |
def _(bm): | |
a = numpy.random.randint(0, 100, (N, 2)) | |
with bm: | |
for i in range(a.shape[0]): | |
if a[i, 1] < a[i, 0]: | |
a[i, 1], a[i, 0] = a[i, 0], a[i, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an execution result.