Last active
March 14, 2018 09:03
-
-
Save hhatto/d6fd0c30def0c0632c7c9b0b4c2d7a79 to your computer and use it in GitHub Desktop.
benchmark of fpath module
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
import sys | |
import os | |
import fpath | |
from benchmarker import Benchmarker | |
N = 1000 * 100 | |
FILENAME = "file.txt" | |
B_FILE_PATH = b"/home/user/path/to/file.txt" | |
FILE_PATH = "/home/user/path/to/file.txt" | |
DIR_PATH = "/home/user/path/to" | |
B_DIR_PATH = b"/home/user/path/to" | |
SEPEND_DIR_PATH = "/home/user/path/to/" | |
def bench_one_arg(arg): | |
for funcname in ("abspath", "basename", "dirname", "isabs", "islink", | |
"exists", "lexists", "split", "splitext", "relpath", | |
"normpath", "realpath"): | |
if arg is not None and funcname != arg: | |
continue | |
# benchmark of file system dependent | |
n = N if funcname not in ("islink", "lexists", "exists", "realpath") else 10 | |
with Benchmarker(n, width=30) as b: | |
@b("naitive.%s" % (funcname)) | |
def _(bm): | |
func = getattr(os.path, funcname) | |
for i in bm: | |
func(B_FILE_PATH) | |
func(FILENAME) | |
func(FILE_PATH) | |
func(DIR_PATH) | |
func(SEPEND_DIR_PATH) | |
@b("rust.%s" % (funcname)) | |
def _(bm): | |
func = getattr(fpath, funcname) | |
for i in bm: | |
func(B_FILE_PATH) | |
func(FILENAME) | |
func(FILE_PATH) | |
func(DIR_PATH) | |
func(SEPEND_DIR_PATH) | |
print("=*=" * 40) | |
def bench_two_arg(arg): | |
for funcname in ("join", ): | |
if arg is not None and funcname != arg: | |
continue | |
n = N | |
with Benchmarker(n, width=30) as b: | |
@b("naitive.%s" % (funcname)) | |
def _(bm): | |
func = getattr(os.path, funcname) | |
for i in bm: | |
func(DIR_PATH, FILE_PATH) | |
func(B_DIR_PATH, B_FILE_PATH) | |
@b("rust.%s" % (funcname)) | |
def _(bm): | |
func = getattr(fpath, funcname) | |
for i in bm: | |
func(DIR_PATH, FILE_PATH) | |
func(B_DIR_PATH, B_FILE_PATH) | |
print("=*=" * 40) | |
arg = sys.argv[1] if len(sys.argv) == 2 else None | |
bench_one_arg(arg) | |
bench_two_arg(arg) |
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
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.abspath 3.3667 3.3600 2.5300 0.8300 | |
rust.abspath 1.7745 1.7600 1.1000 0.6600 | |
## Ranking real | |
rust.abspath 1.7745 (100.0) ******************** | |
naitive.abspath 3.3667 ( 52.7) *********** | |
## Matrix real [01] [02] | |
[01] rust.abspath 1.7745 100.0 189.7 | |
[02] naitive.abspath 3.3667 52.7 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.basename 0.3569 0.3600 0.3600 0.0000 | |
rust.basename 0.3548 0.3500 0.3500 0.0000 | |
## Ranking real | |
rust.basename 0.3548 (100.0) ******************** | |
naitive.basename 0.3569 ( 99.4) ******************** | |
## Matrix real [01] [02] | |
[01] rust.basename 0.3548 100.0 100.6 | |
[02] naitive.basename 0.3569 99.4 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.dirname 0.4950 0.5000 0.4900 0.0100 | |
rust.dirname 0.4250 0.4200 0.4200 0.0000 | |
## Ranking real | |
rust.dirname 0.4250 (100.0) ******************** | |
naitive.dirname 0.4950 ( 85.9) ***************** | |
## Matrix real [01] [02] | |
[01] rust.dirname 0.4250 100.0 116.5 | |
[02] naitive.dirname 0.4950 85.9 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.isabs 0.2867 0.2900 0.2900 0.0000 | |
rust.isabs 0.1994 0.2000 0.2000 0.0000 | |
## Ranking real | |
rust.isabs 0.1994 (100.0) ******************** | |
naitive.isabs 0.2867 ( 69.5) ************** | |
## Matrix real [01] [02] | |
[01] rust.isabs 0.1994 100.0 143.8 | |
[02] naitive.isabs 0.2867 69.5 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=10, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.islink 0.6103 0.0000 0.0000 0.0000 | |
rust.islink 0.6202 0.0000 0.0000 0.0000 | |
## Ranking real | |
naitive.islink 0.6103 (100.0) ******************** | |
rust.islink 0.6202 ( 98.4) ******************** | |
## Matrix real [01] [02] | |
[01] naitive.islink 0.6103 100.0 101.6 | |
[02] rust.islink 0.6202 98.4 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=10, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.exists 0.6297 0.0000 0.0000 0.0000 | |
rust.exists 0.6116 0.0200 0.0100 0.0100 | |
## Ranking real | |
rust.exists 0.6116 (100.0) ******************** | |
naitive.exists 0.6297 ( 97.1) ******************* | |
## Matrix real [01] [02] | |
[01] rust.exists 0.6116 100.0 103.0 | |
[02] naitive.exists 0.6297 97.1 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=10, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.lexists 0.6499 0.0000 0.0000 0.0000 | |
rust.lexists 0.6488 0.0000 0.0000 0.0000 | |
## Ranking real | |
rust.lexists 0.6488 (100.0) ******************** | |
naitive.lexists 0.6499 ( 99.8) ******************** | |
## Matrix real [01] [02] | |
[01] rust.lexists 0.6488 100.0 100.2 | |
[02] naitive.lexists 0.6499 99.8 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.split 0.6144 0.6100 0.6000 0.0100 | |
rust.split 0.5682 0.5500 0.5500 0.0000 | |
## Ranking real | |
rust.split 0.5682 (100.0) ******************** | |
naitive.split 0.6144 ( 92.5) ****************** | |
## Matrix real [01] [02] | |
[01] rust.split 0.5682 100.0 108.1 | |
[02] naitive.split 0.6144 92.5 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.splitext 0.6586 0.6600 0.6500 0.0100 | |
rust.splitext 0.5011 0.4800 0.4800 0.0000 | |
## Ranking real | |
rust.splitext 0.5011 (100.0) ******************** | |
naitive.splitext 0.6586 ( 76.1) *************** | |
## Matrix real [01] [02] | |
[01] rust.splitext 0.5011 100.0 131.4 | |
[02] naitive.splitext 0.6586 76.1 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.relpath 21.9935 20.3000 14.7000 5.6000 | |
rust.relpath 9.8615 9.3300 5.4000 3.9300 | |
## Ranking real | |
rust.relpath 9.8615 (100.0) ******************** | |
naitive.relpath 21.9935 ( 44.8) ********* | |
## Matrix real [01] [02] | |
[01] rust.relpath 9.8615 100.0 223.0 | |
[02] naitive.relpath 21.9935 44.8 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.normpath 1.1578 1.1300 1.1200 0.0100 | |
rust.normpath 1.1620 1.1600 1.1500 0.0100 | |
## Ranking real | |
naitive.normpath 1.1578 (100.0) ******************** | |
rust.normpath 1.1620 ( 99.6) ******************** | |
## Matrix real [01] [02] | |
[01] naitive.normpath 1.1578 100.0 100.4 | |
[02] rust.normpath 1.1620 99.6 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=10, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.realpath 2.4819 0.0100 0.0100 0.0000 | |
rust.realpath 2.2393 0.0100 0.0000 0.0100 | |
## Ranking real | |
rust.realpath 2.2393 (100.0) ******************** | |
naitive.realpath 2.4819 ( 90.2) ****************** | |
## Matrix real [01] [02] | |
[01] rust.realpath 2.2393 100.0 110.8 | |
[02] naitive.realpath 2.4819 90.2 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
## benchmarker: release 4.0.1 (for python) | |
## python version: 3.6.4 | |
## python compiler: GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) | |
## python platform: Darwin-16.7.0-x86_64-i386-64bit | |
## python executable: /Users/hattori-h/.virtualenvs/py364/bin/python | |
## cpu model: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz | |
## parameters: loop=100000, cycle=1, extra=0 | |
## real (total = user + sys) | |
naitive.join 0.1319 0.1300 0.1300 0.0000 | |
rust.join 0.1480 0.1500 0.1500 0.0000 | |
## Ranking real | |
naitive.join 0.1319 (100.0) ******************** | |
rust.join 0.1480 ( 89.1) ****************** | |
## Matrix real [01] [02] | |
[01] naitive.join 0.1319 100.0 112.2 | |
[02] rust.join 0.1480 89.1 100.0 | |
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*==*= | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment