How do I measure elapsed time in Python?

Use time.time() to measure the elapsed wall-clock time between two points: import time start = time.time() print(“hello”) end = time.time() print(end – start) This gives the execution time in seconds. Another option since Python 3.3 might be to use perf_counter or process_time, depending on your requirements. Before 3.3 it was recommended to use time.clock (thanks … Read more

Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?

The Python 3 range() object doesn’t produce numbers immediately; it is a smart sequence object that produces numbers on demand. All it contains is your start, stop and step values, then as you iterate over the object the next integer is calculated each iteration. The object also implements the object.__contains__ hook, and calculates if your … Read more

Improve INSERT-per-second performance of SQLite

Several tips: Put inserts/updates in a transaction. For older versions of SQLite – Consider a less paranoid journal mode (pragma journal_mode). There is NORMAL, and then there is OFF, which can significantly increase insert speed if you’re not too worried about the database possibly getting corrupted if the OS crashes. If your application crashes the … Read more

What is the difference between call and apply?

The difference is that apply lets you invoke the function with arguments as an array; call requires the parameters be listed explicitly. A useful mnemonic is “A for array and C for comma.” See MDN’s documentation on apply and call. Pseudo syntax: theFunction.apply(valueForThis, arrayOfArgs) theFunction.call(valueForThis, arg1, arg2, …) There is also, as of ES6, the … Read more

Why is the Android emulator so slow? How can we speed up the Android emulator? [closed]

Update You can now enable the Quick Boot option for Android Emulator. That will save emulator state, and it will start the emulator quickly on the next boot. Click on Emulator edit button, then click Show Advanced Setting. Then enable Quick Boot like below screenshot. Android Development Tools (ADT) 9.0.0 (or later) has a feature … Read more