如果我有一个程序在服务器上运行,哪个会使用更多内存:
a = operation1()
b = operation2()
c = doOperation(a, b)
或直接:
a = doOperation(operation1(), operation2())
编辑:
1:我正在使用 CPython。
2:我问这个问题是因为有时,我喜欢我的代码的可读性,所以不是编写冗长的操作序列,而是将它们拆分为变量。
编辑2:
这是完整的代码:
class Reset(BaseHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self, uri):
uri = self.request.uri
try:
debut = time.time()
tim = uri[7:]
print tim
cod = yield tornado.gen.Task(db.users.find_one, ({"reset.timr":tim})) # this is temporary variable
code = cod[0]["reset"][-1]["code"] # this one too
dat = simpleencode.decode(tim, code)
now = datetime.datetime.now() # this one too
temps = datetime.datetime.strptime(dat[:19], "%Y-%m-%d %H:%M:%S") # this one too
valid = now - temps # what if i put them all here
if valid.days < 2:
print time.time() - debut # here time.time() has not been set to another variable, used directly
self.render("reset.html")
else:
self.write("hohohohoo")
self.finish()
except (ValueError, TypeError, UnboundLocalError):
self.write("pirate")
self.finish()
如您所见,有些变量只是暂时有用。