benchmarking

Why is reading lines from stdin much slower in C++ than Python?

Why is reading lines from stdin much slower in C++ than Python? Question: I wanted to compare reading lines of string input from stdin using Python and C++ and was shocked to see my C++ code run an order of magnitude slower than the equivalent Python code. Since my C++ is rusty and I’m not …

Total answers: 10

How can I find the missing value more concisely?

How can I find the missing value more concisely? Question: The following code checks if x and y are distinct values (the variables x, y, z can only have values a, b, or c) and if so, sets z to the third character: if x == ‘a’ and y == ‘b’ or x == ‘b’ …

Total answers: 11

Benchmarking (python vs. c++ using BLAS) and (numpy)

Benchmarking (python vs. c++ using BLAS) and (numpy) Question: I would like to write a program that makes extensive use of BLAS and LAPACK linear algebra functionalities. Since performance is an issue I did some benchmarking and would like know, if the approach I took is legitimate. I have, so to speak, three contestants and …

Total answers: 5

How to use python timeit when passing variables to functions?

How to use python timeit when passing variables to functions? Question: I’m struggling with this using timeit and was wondering if anyone had any tips Basically I have a function(that I pass a value to) that I want to test the speed of and created this: if __name__==’__main__’: from timeit import Timer t = Timer(superMegaIntenseFunction(10)) …

Total answers: 5

Python Slice Assignment Memory Usage

Python Slice Assignment Memory Usage Question: I read in a comment here on Stack Overflow that it is more memory efficient to do slice assignment when changing lists. For example, a[:] = [i + 6 for i in a] should be more memory efficient than a = [i + 6 for i in a] because …

Total answers: 1

Is there any simple way to benchmark Python script?

Is there any simple way to benchmark Python script? Question: Usually I use shell command time. My purpose is to test if data is small, medium, large or very large set, how much time and memory usage will be. Any tools for Linux or just Python to do this? Asked By: noomz || Source Answers: …

Total answers: 12

How do I get monotonic time durations in python?

How do I get monotonic time durations in python? Question: I want to log how long something takes in real walltime. Currently I’m doing this: startTime = time.time() someSQLOrSomething() print “That took %.3f seconds” % (time.time() – startTime) But that will fail (produce incorrect results) if the time is adjusted while the SQL query (or …

Total answers: 5

Why is looping over range() in Python faster than using a while loop?

Why is looping over range() in Python faster than using a while loop? Question: The other day I was doing some Python benchmarking and I came across something interesting. Below are two loops that do more or less the same thing. Loop 1 takes about twice as long as loop 2 to execute. Loop 1: …

Total answers: 6

SQLite Performance Benchmark — why is :memory: so slow…only 1.5X as fast as disk?

SQLite Performance Benchmark — why is :memory: so slow…only 1.5X as fast as disk? Question: Why is :memory: in sqlite so slow? I’ve been trying to see if there are any performance improvements gained by using in-memory sqlite vs. disk based sqlite. Basically I’d like to trade startup time and memory to get extremely rapid …

Total answers: 8