benchmarking

Why is reading one byte 20x slower than reading 2, 3, 4, … bytes from a file?

做~自己de王妃 提交于 2019-12-03 01:03:45
I have been trying to understand the tradeoff between read and seek . For small "jumps" reading unneeded data is faster than skipping it with seek . While timing different read/seek chunk sizes to find the tipping point, I came across a odd phenomenon: read(1) is about 20 times slower than read(2) , read(3) , etc. This effect is the same for different read methods, e.g. read() and readinto() . Why is this the case? Search in the timing results for the following line 2/3 of the way through: 2 x buffered 1 byte readinto bytearray Environment: Python 3.5.2 |Continuum Analytics, Inc.| (default,

Is `if` faster than ifelse?

久未见 提交于 2019-12-02 23:08:18
When I was re-reading Hadley's Advanced R recently, I noticed that he said in Chapter 6 that `if` can be used as a function like `if`(i == 1, print("yes"), print("no")) (If you have the physical book in hand, it's on Page 80) We know that ifelse is slow ( Does ifelse really calculate both of its vectors every time? Is it slow? ) as it evaluates all arguments. Will `if` be a good alternative to that as if seems to only evaluate TRUE arguments (this is just my assumption)? Update : Based on the answers from @Benjamin and @Roman and the comments from @Gregor and many others, ifelse seems to be a

How to do “performance-based” (benchmark) unit testing in Python

断了今生、忘了曾经 提交于 2019-12-02 21:06:14
Let's say that I've got my code base to as high a degree of unit test coverage as makes sense. (Beyond a certain point, increasing coverage doesn't have a good ROI.) Next I want to test performance. To benchmark code to make sure that new commits aren't slowing things down needlessly. I was very intrigued by Safari's zero tolerance policy for slowdowns from commits. I'm not sure that level of commitment to speed has a good ROI for most projects, but I'd at least like to be alerted that a speed regression has happened, and be able to make a judgment call about it. Environment is Python on Linux

Guava ImmutableMap has noticeably slower access than HashMap

余生长醉 提交于 2019-12-02 20:09:22
While working on a memory benchmark of some high-throughput data structures, I realized I could use an ImmutableMap with only a little refactoring. Thinking this would be an improvement, I threw it into the mix and was surprised to discover that not only was it slower than HashMap , in a single-threaded environment it appears to be consistently slower even than ConcurrentHashMap ! You can see the full benchmark here: https://bitbucket.org/snippets/dimo414/89K7G The meat of the test is pretty simple, time how long it takes to get a large number of random strings that may exist in the map.

How to calculate MIPS for an algorithm for ARM processor

橙三吉。 提交于 2019-12-02 19:42:00
I have been asked recently to produced the MIPS (million of instructions per second) for an algorithm we have developed. The algorithm is exposed by a set of C-style functions. We have exercise the code on a Dell Axim to benchmark the performance under different input. This question came from our hardware vendor, but I am mostly a HL software developer so I am not sure how to respond to the request. Maybe someone with similar HW/SW background can help... Since our algorithm is not real time, I don't think we need to quantify it as MIPS. Is it possible to simply quote the total number of

Why is .NET faster than C++ in this case?

浪子不回头ぞ 提交于 2019-12-02 19:32:36
Make sure you run outside of the IDE. That is key. -edit- I LOVE SLaks comment. "The amount of misinformation in these answers is staggering." :D Calm down guys. Pretty much all of you were wrong. I DID make optimizations. It turns out whatever optimizations I made wasn't good enough. I ran the code in GCC using gettimeofday (I'll paste code below) and used g++ -O2 file.cpp and got slightly faster results then C#. Maybe MS didn't create the optimizations needed in this specific case but after downloading and installing mingw I was tested and found the speed to be near identical. Justicle Seems

Get local time in nanoseconds [duplicate]

99封情书 提交于 2019-12-02 19:30:16
Possible Duplicate: C++ Timer function to provide time in nano seconds I need to measure the duration of a function execution in nanoseconds resolution. Is it possible? Our ordinary computer hardware and software are able to give such a precision for time? If yes how to accomplish that with c++? Is it possible with Boost library? Yes, today most hardware supports this sort of resolution, and the C++ standard library has an API that can support it as well. Unfortunately not all implementations of C++ actually do provide it. The API is the <chrono> library introduced in C++11: #include <iostream

Running functions in R multiple times during benchmarking

孤人 提交于 2019-12-02 19:24:51
I am trying to measure the computation time of a function in R using system.time() . I want to run the function a few hundred times to get an average but I don't want to copy and paste that many times. Is there an easier way to do that? The microbenchmark package takes a ,times= option and has the added bonus of being a bit more accurate. > library(microbenchmark) > m <- microbenchmark( seq(10)^2, (1:10)^2, times=10000) > m Unit: nanoseconds expr min lq median uq max 1 (1:10)^2 2567 3423 3423 4278 41918 2 seq(10)^2 44484 46195 46195 47051 1804147 > plot(m) And using the not-yet-released

Why is 2 * x * x faster than 2 * ( x * x ) in Python 3.x, for integers?

丶灬走出姿态 提交于 2019-12-02 17:16:46
The following Python 3.x integer multiplication takes on average between 1.66s and 1.77s: import time start_time = time.time() num = 0 for x in range(0, 10000000): # num += 2 * (x * x) num += 2 * x * x print("--- %s seconds ---" % (time.time() - start_time)) if I replace 2 * x * x with 2 *(x * x) , it takes between 2.04 and 2.25 . How come? On the other hand it is the opposite in Java: 2 * (x * x) is faster in Java. Java test link: Why is 2 * (i * i) faster than 2 * i * i in Java? I ran each version of the program 10 times, here are the results. 2 * x * x | 2 * (x * x) ------------------------

What's really more performant? Haskell or OCaml [closed]

安稳与你 提交于 2019-12-02 17:14:57
I spent the last 18 months getting the grip of functional programming, starting with learning OCaml and for some weeks now Haskell. Now I want to take the next step and implement some actual application: A simple realtime terrain editor. I've written numerous realtime terrain rendering engines, so this is a familiar topic. And the used recursive algorithms and data structures seem very fit for a functional implementation. With this being a realtime application I'm naturally looking for the best performance I can get. Now some (IMHO quite annoying) proponent of OCaml quite frequently bitches