小编aru*_*nmj的帖子

为什么 namedtuple._as_dict() 比使用 dict() 的转换慢

当我尝试使用以下方法将 namedtuple 转换为字典 [python 2.7.12] 时,namedtuple._as_dict()发现比第一种方法慢 10 倍以上。谁能告诉我这背后的原因是什么?

In [1]: Container = namedtuple('Container', ['name', 'date', 'foo', 'bar'])

In [2]: c = Container('john','10-2-2017',20.78,'python')

In [3]: %timeit dict(name=c.name,date=c.date,foo=c.foo,bar=c.bar)
The slowest run took 7.57 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 536 ns per loop

In [4]: %timeit c._asdict()
The slowest run took 4.84 times longer than the fastest. This could mean that an intermediate result is being …
Run Code Online (Sandbox Code Playgroud)

python namedtuple

3
推荐指数
1
解决办法
2425
查看次数

是否可以使用 virtualbox vagrant provider 在特定组中添加 vms?

我的虚拟机中有几个虚拟机。我希望在不同的组中查看它们,而不是 ui 中的单个列表。所以特定环境的所有机器将被组合在一起。是否有可能在 vagrantfile 中提及组名?

virtualbox vagrant

1
推荐指数
1
解决办法
1463
查看次数

标签 统计

namedtuple ×1

python ×1

vagrant ×1

virtualbox ×1