Created
May 8, 2010 12:02
-
-
Save oyvindio/394529 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 | |
| import os | |
| import sys | |
| import shelve | |
| def exportTabSeparated(filename): | |
| shelf = shelve.open(filename) | |
| outFilename = os.path.splitext(os.path.basename(filename))[0] + ".txt" | |
| with open(outFilename, "w") as f: | |
| g = tabSeparatedStringGenerator(shelf) | |
| for dummy in range(len(shelf.values()[0])): | |
| f.write(g.next() + "\n") | |
| shelf.close() | |
| def tabSeparatedStringGenerator(shelf): | |
| for i in range(len(shelf.values()[0])): | |
| yield ''.join([str(v[i]) + "\t" for v in shelf.values()]).strip() | |
| if __name__ == "__main__": | |
| if len(sys.argv) == 1: | |
| print >> sys.stderr, "Invalid arguments %s" % sys.argv | |
| exit(1) | |
| else: | |
| for arg in sys.argv[1:]: | |
| exportTabSeparated(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
| In [5]: s.sort_stats('cumulative').print_stats() | |
| Sat May 8 11:38:57 2010 export-tab-sep.pstats | |
| 6200276 function calls in 45048.666 CPU seconds | |
| Ordered by: cumulative time | |
| ncalls tottime percall cumtime percall filename:lineno(function) | |
| 1 0.000 0.000 45048.666 45048.666 <string>:1(<module>) | |
| 1 0.001 0.001 45048.666 45048.666 {execfile} | |
| 1 0.002 0.002 45048.666 45048.666 export-tab-sep.py:2(<module>) | |
| 1 1.262 1.262 45048.658 45048.658 export-tab-sep.py:7(exportTabSeparated) | |
| 100001 1084.105 0.011 45045.587 0.450 export-tab-sep.py:16(tabSeparatedStringGenerator) | |
| 100002 2.740 0.000 43961.028 0.440 /home/oyvindio/.local/lib/python2.6/UserDict.py:118(values) | |
| 500010 286.420 0.001 43958.288 0.088 /home/oyvindio/.local/lib/python2.6/UserDict.py:108(iteritems) | |
| 400008 1271.442 0.003 41429.053 0.104 /usr/lib/python2.6/shelve.py:117(__getitem__) | |
| 400008 33911.654 0.085 33911.654 0.085 {built-in method load} | |
| 500012 7.743 0.000 8474.847 0.017 /usr/lib/python2.6/bsddb/dbutils.py:47(DeadlockWrap) | |
| 400008 5.248 0.000 6242.681 0.016 /usr/lib/python2.6/bsddb/__init__.py:265(__getitem__) | |
| 400008 6228.427 0.016 6228.427 0.016 /usr/lib/python2.6/bsddb/__init__.py:267(<lambda>) | |
| 500010 1.917 0.000 2242.815 0.004 /home/oyvindio/.local/lib/python2.6/UserDict.py:95(__iter__) | |
| 100002 0.694 0.000 2240.898 0.022 /usr/lib/python2.6/shelve.py:100(keys) | |
| 100002 1.448 0.000 2240.203 0.022 /usr/lib/python2.6/bsddb/__init__.py:298(keys) | |
| 100002 2236.624 0.022 2236.624 0.022 {method 'keys' of 'DB' objects} | |
| 400008 1.741 0.000 1.741 0.000 {cPickle.Unpickler} | |
| 400008 1.535 0.000 1.535 0.000 {cStringIO.StringIO} | |
| 500011 1.345 0.000 1.345 0.000 /usr/lib/python2.6/bsddb/__init__.py:248(_checkOpen) | |
| 100000 1.314 0.000 1.314 0.000 {method 'write' of 'file' objects} | |
| 500012 1.051 0.000 1.051 0.000 {method 'has_key' of 'dict' objects} | |
| 500012 0.997 0.000 0.997 0.000 {method 'get' of 'dict' objects} | |
| 100000 0.584 0.000 0.584 0.000 {method 'join' of 'str' objects} | |
| 100000 0.345 0.000 0.345 0.000 {method 'strip' of 'str' objects} | |
| 1 0.000 0.000 0.018 0.018 /usr/lib/python2.6/shelve.py:221(open) | |
| 1 0.000 0.000 0.018 0.018 /usr/lib/python2.6/shelve.py:216(__init__) | |
| 1 0.000 0.000 0.016 0.016 /usr/lib/python2.6/anydbm.py:43(<module>) | |
| 5 0.001 0.000 0.016 0.003 {__import__} | |
| 1 0.000 0.000 0.015 0.015 /usr/lib/python2.6/dbhash.py:1(<module>) | |
| 1 0.013 0.013 0.014 0.014 /usr/lib/python2.6/bsddb/__init__.py:40(<module>) | |
| 1 0.000 0.000 0.005 0.005 /usr/lib/python2.6/shelve.py:150(__del__) | |
| 1 0.000 0.000 0.005 0.005 /usr/lib/python2.6/shelve.py:142(close) | |
| 2 0.000 0.000 0.004 0.002 /usr/lib/python2.6/bsddb/__init__.py:287(close) | |
| 1 0.004 0.004 0.004 0.004 {method 'close' of 'DB' objects} | |
| 2 0.003 0.001 0.003 0.001 {range} | |
| 1 0.000 0.000 0.002 0.002 /usr/lib/python2.6/anydbm.py:66(open) | |
| 1 0.000 0.000 0.001 0.001 /usr/lib/python2.6/dbhash.py:18(open) | |
| 1 0.000 0.000 0.001 0.001 /usr/lib/python2.6/bsddb/__init__.py:350(hashopen) | |
| 1 0.000 0.000 0.001 0.001 /usr/lib/python2.6/bsddb/__init__.py:403(_openDBEnv) | |
| 1 0.001 0.001 0.001 0.001 {method 'open' of 'DBEnv' objects} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/shelve.py:57(<module>) | |
| 2 0.000 0.000 0.000 0.000 /home/oyvindio/.local/lib/python2.6/abc.py:78(__new__) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/collections.py:1(<module>) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/dbutils.py:27(<module>) | |
| 1 0.000 0.000 0.000 0.000 {method 'open' of 'DB' objects} | |
| 1 0.000 0.000 0.000 0.000 {_bsddb.DBEnv} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/whichdb.py:17(whichdb) | |
| 2 0.000 0.000 0.000 0.000 /home/oyvindio/.local/lib/python2.6/abc.py:81(<genexpr>) | |
| 47 0.000 0.000 0.000 0.000 {getattr} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/db.py:40(<module>) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/weakref.py:6(<module>) | |
| 4 0.000 0.000 0.000 0.000 {open} | |
| 2 0.000 0.000 0.000 0.000 {built-in method __new__ of type object at 0x8228620} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/shelve.py:156(sync) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/__init__.py:342(sync) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/dumbdbm.py:22(<module>) | |
| 2 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/__init__.py:232(_closeCursors) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/__init__.py:218(__del__) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/__init__.py:194(__init__) | |
| 1 0.000 0.000 0.000 0.000 {_bsddb.DB} | |
| 1 0.000 0.000 0.000 0.000 /home/oyvindio/.local/lib/python2.6/posixpath.py:94(splitext) | |
| 1 0.000 0.000 0.000 0.000 {method 'read' of 'file' objects} | |
| 1 0.000 0.000 0.000 0.000 {method 'sync' of 'DB' objects} | |
| 1 0.000 0.000 0.000 0.000 /home/oyvindio/.local/lib/python2.6/genericpath.py:85(_splitext) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/__init__.py:189(_DBWithCursor) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/weakref.py:219(WeakKeyDictionary) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/keyword.py:11(<module>) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/weakref.py:33(WeakValueDictionary) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/dumbdbm.py:34(_Database) | |
| 2 0.000 0.000 0.000 0.000 {_struct.unpack} | |
| 1 0.000 0.000 0.000 0.000 /home/oyvindio/.local/lib/python2.6/posixpath.py:109(basename) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/whichdb.py:2(<module>) | |
| 4 0.000 0.000 0.000 0.000 {len} | |
| 1 0.000 0.000 0.000 0.000 {method 'set_flags' of 'DB' objects} | |
| 3 0.000 0.000 0.000 0.000 {method 'rfind' of 'str' objects} | |
| 1 0.000 0.000 0.000 0.000 {method 'close' of 'file' objects} | |
| 1 0.000 0.000 0.000 0.000 {posix.stat} | |
| 4 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects} | |
| 4 0.000 0.000 0.000 0.000 {method 'add' of 'set' objects} | |
| 2 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/shelve.py:85(Shelf) | |
| 2 0.000 0.000 0.000 0.000 {hasattr} | |
| 2 0.000 0.000 0.000 0.000 {method 'values' of 'dict' objects} | |
| 1 0.000 0.000 0.000 0.000 {method 'set_lk_detect' of 'DBEnv' objects} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/shelve.py:167(BsdDbShelf) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/__init__.py:91(_iter_mixin) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/bsddb/__init__.py:414(_checkflag) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/shelve.py:209(DbfilenameShelf) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/shelve.py:75(_ClosedDict) | |
| 1 0.000 0.000 0.000 0.000 {method 'startswith' of 'str' objects} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/anydbm.py:45(error) | |
| 1 0.000 0.000 0.000 0.000 {method 'set_get_returns_none' of 'DB' objects} | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/weakref.py:198(KeyedRef) | |
| 1 0.000 0.000 0.000 0.000 <string>:1(DBNotFoundError) | |
| 1 0.000 0.000 0.000 0.000 {method '__enter__' of 'file' objects} | |
| 1 0.000 0.000 0.000 0.000 <string>:2(DBKeyEmptyError) | |
| 1 0.000 0.000 0.000 0.000 /usr/lib/python2.6/shelve.py:92(__init__) | |
| 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} |
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
| $ time python -m cProfile -o export-tab-sep.pstats export-tab-sep.py listdir-local-2010-04-12-2154.shelf | |
| real 750m48.726s | |
| user 646m51.174s | |
| sys 103m31.264s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment