Last active
August 29, 2015 14:05
-
-
Save mumumu/5e55b3a8c8d4eb29d73e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
from benchmarker import Benchmarker | |
from collections import Counter | |
with Benchmarker(width=20) as bm: | |
counters = [Counter(), Counter(), Counter(), Counter()] | |
with bm('double loop'): | |
for i in xrange(10000000): | |
for counter in counters: | |
counter['hoge'] += 1 | |
counter1 = Counter() | |
counter2 = Counter() | |
counter3 = Counter() | |
counter4 = Counter() | |
with bm('single loop'): | |
for i in xrange(10000000): | |
counter1['hoge'] += 1 | |
counter2['hoge'] += 1 | |
counter3['hoge'] += 1 | |
counter4['hoge'] += 1 | |
counter4 = Counter() | |
counter5 = Counter() | |
counter6 = Counter() | |
counter7 = Counter() | |
def count(): | |
counter4['hoge'] += 1 | |
counter5['hoge'] += 1 | |
counter6['hoge'] += 1 | |
counter7['hoge'] += 1 | |
with bm('function invoke'): | |
for i in xrange(10000000): | |
count() | |
def count(c): | |
c['hoge'] += 1 | |
with bm('double loop with map'): | |
for i in xrange(10000000): | |
map(count, counters) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
インライン展開みたいなシンプルなテクニックが通用する結果に
map 遅すぎワロタ