3 ms·
You can modify the posted script to eliminate global variables: def f(): l = [0] for i in range(100000000): l += [2] return l
by bgwalter 1y ago
You can modify the posted script to eliminate global variables:
def f():
l = [0]
for i in range(100000000):
l += [2]
return l
x = f()
print(x[0])
Timings:
3.9: 8.6s
3.14: 8.7s
3.14 (free-threading): 11.6s
3.14 is not faster than 3.9 and the free-threading build is 33% slower.
- nas 1y agoI get: 3.9: 2.78 3.14: 3.86 3.14t: 3.91 This is a silly benchmark though. Look at pyperformance if you want something that might represent real script/application performance. Generally 3.14t is about 0.9x the performance of the default build. That depends on a lot of things though.
- bgwalter 1y agoPyperformance is a bloated, over-engineered test suite that does not catch anything. Due to the bloat it is hard to see what is even measured. This benchmark demonstrates that global variables are not needed to find severe regressions.
- ciupicri 1y agoWhat is this $hi+? You're creating a list that looks like this: [0, 2, …, 2]. It's also common / Pythonic to use uppercase L for lists. If you don't want to use global variables just add the result of f to x and stop using the global variable, i.e. x += f()
- bgwalter 1y agoNot even wrong.
- int_19h 1y ago> It's also common / Pythonic to use uppercase L for lists. Variables always start with a lowercase letter in idiomatic Python unless they're constants or types. Using single-letter uppercase for variables is not unusual in ML Python code, but that also happens to be one of the worst ecosystems when it comes to idiomatic Python and general code quality.