0

The common way to create a set is,

st = set()

but, when we do something like this,

%%time 
for _ in range(1_000_000):
  x = set()
CPU times: user 188 ms, sys: 0 ns, total: 188 ms
Wall time: 192 ms
%%time 
for _ in range(1_000_000):
  x = {*()}
CPU times: user 163 ms, sys: 970 µs, total: 164 ms
Wall time: 169 ms

clearly the uncommon way is outperforming the common way to create a set.

What is the reasoning behind this difference in time?

Shouldn't the uncommon way be made the standard way to create a set due to it outperforming the common way?

mkrieger1
  • 14,486
  • 4
  • 43
  • 54
apostofes
  • 2,233
  • 2
  • 12
  • 29

0 Answers0