New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparisons optimization #875

Merged
merged 11 commits into from Jul 28, 2018

Conversation

Projects
None yet
2 participants
@patiences
Contributor

patiences commented Jul 25, 2018

Comparison operations (==, <, >, etc.) are expensive because org/python/types/Methods are created each time they are used. Sacrificing some generality and coding style, directing each operation to its implementation will save unnecessary objects from being created and functions from being called.

Results (updated):

Pystone
Without optimization

test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 37.4149
This machine benchmarks at 1336.37 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 37.1006
This machine benchmarks at 1347.69 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 36.7188
This machine benchmarks at 1361.70 pystones/second

With optimization

test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 23.6110
This machine benchmarks at 2157.66 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 22.0497
This machine benchmarks at 2267.61 pystones/second
test_pystone (tests.test_pystone.PystoneTest) ... Pystone(1.2) time for 50000 passes = 22.6868
This machine benchmarks at 2203.92 pystones/second

Over 50% improvement!

Benchmarking test
Without optimization

Running test_cmp
  Elapsed time:  107.74267825996503  sec
  CPU process time:  0.00042400000000003546  sec
Running test_cmp
  Elapsed time:  110.58186632907018  sec
  CPU process time:  0.00013099999999999223  sec
Running test_cmp
  Elapsed time:  108.22996701404918  sec
  CPU process time:  0.0009190000000000031  sec

With optimization

Running test_cmp
  Elapsed time:  41.10957779898308  sec
  CPU process time:  0.0007880000000000109  sec
Running test_cmp
  Elapsed time:  39.39081814000383  sec
  CPU process time:  0.00012699999999998823  sec
Running test_cmp
  Elapsed time:  38.50678546191193  sec
  CPU process time:  0.0004529999999999812  sec

Over 60% improvement here!

@patiences patiences changed the title from [WIP] Comparisons optimization to Comparisons optimization Jul 27, 2018

"'%s' not supported between instances of '%s' and '%s'", "in", v.typeName(), w.typeName()));
}
}

This comment has been minimized.

@patiences

patiences Jul 27, 2018

Contributor

This (__contains) and __not_contains__ is a bit buggy. There should be no reflective checks (1 in [1,2,3] != [1,2,3] in 1, right?) and those TypeErrors are not the right exceptions to throw if there is an unorderable type, etc. I've removed the reflective checks since I'm looking at this piece of code but other than that the code should be unchanged. The problem and tests are tracked here: #877

@freakboy3742

Amazing speedup - nice catch!

@freakboy3742 freakboy3742 merged commit edbfc47 into pybee:master Jul 28, 2018

5 checks passed

beekeeper:0/beefore:javacheckstyle Java lint checks passed.
Details
beekeeper:0/beefore:pycodestyle Python lint checks passed.
Details
beekeeper:1/smoke-test Smoke build (Python 3.4) passed.
Details
beekeeper:2/full-test:py3.5 Python 3.5 tests passed.
Details
beekeeper:2/full-test:py3.6 Python 3.6 tests passed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment