【发布时间】:2014-10-12 17:09:12
【问题描述】:
我在 python 方面相对较新,我正在使用 pytables 将一些基因组注释存储在 hdf 中以便更快地查询。我发现查询表中不匹配的字符串很慢,但我不确定如何优化它以获得更好的性能。
下面显示的是其中一张表:
In [5]: t
Out[5]:
/gene/annotation (Table(315202,), fletcher32, blosc(5)) ''
description := {
"name": StringCol(itemsize=36, shape=(), dflt='', pos=0),
"track": StringCol(itemsize=12, shape=(), dflt='', pos=1),
"etype": StringCol(itemsize=12, shape=(), dflt='', pos=2),
"event": StringCol(itemsize=36, shape=(), dflt='', pos=3)}
byteorder := 'irrelevant'
chunkshape := (1365,)
autoindex := True
colindexes := {
"name": Index(9, full, shuffle, zlib(1)).is_csi=True}
当条件匹配表中的某些内容时,timeit 以微秒为单位返回。
In [6]: timeit [x for x in t.where("name == 'record_exists_in_table'")]
10000 loops, best of 3: 109 µs per loop
但是,当我尝试搜索一个不存在的字符串时,它是以毫秒为单位的。
In [8]: timeit [x for x in t.where("name == 'no_such_record'")]
10 loops, best of 3: 56 ms per loop
任何能指引我走向正确方向的建议将不胜感激!
【问题讨论】:
-
嗯,这很有趣。你能在 PyTables github repo 中提交一张票吗?如果您可以添加一个独立的示例,那就太好了。我想看看那个。
-
以防万一你的问题和我的一样:stackoverflow.com/questions/26197622/…
-
@Francesc 我可以在 3.1.1 中确认这种回归。降级到 3.0.0 解决了这个问题。带有要重现的代码的相应 github 问题的链接是:github.com/PyTables/PyTables/issues/390