benchmarking

Why is `std::copy` 5x (!) slower than `memcpy` in my test program?

故事扮演 提交于 2019-12-03 07:10:08
This is a follow-up to this question where I posted this program: #include <algorithm> #include <cstdlib> #include <cstdio> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <vector> #include <chrono> class Stopwatch { public: typedef std::chrono::high_resolution_clock Clock; //! Constructor starts the stopwatch Stopwatch() : mStart(Clock::now()) { } //! Returns elapsed number of seconds in decimal form. double elapsed() { return 1.0 * (Clock::now() - mStart).count() / Clock::period::den; } Clock::time_point mStart; }; struct test_cast { int operator()(const

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

不打扰是莪最后的温柔 提交于 2019-12-03 06:57:48
问题 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

Why does Perl's tr/\\n// get slower and slower as line lengths increase?

血红的双手。 提交于 2019-12-03 06:32:36
In perlfaq5 , there's an answer for How do I count the number of lines in a file? . The current answer suggests a sysread and a tr/\n// . I wanted to try a few other things to see how much faster tr/\n// would be, and also try it against files with different average line lengths. I created a benchmark to try various ways to do it. I'm running this on Mac OS X 10.5.8 and Perl 5.10.1 on a MacBook Air: Shelling out to wc (fastest except for short lines) tr/\n// (next fastest, except for long average line lengths) s/\n//g (usually speedy) while( <$fh> ) { $count++ } (almost always a slow poke,

How can I benchmark the performance of C++ code? [closed]

回眸只為那壹抹淺笑 提交于 2019-12-03 06:31:13
I am starting to study algorithms and data structures seriously, and interested in learning how to compare the performance of the different ways I can implement A&DTs. For simple tests, I can get the time before/after something runs, run that thing 10^5 times, and average the running times. I can parametrize input by size, or sample random input, and get a list of running times vs. input size. I can output that as a csv file, and feed it into pandas. I am not sure there are no caveats. I am also not sure what to do about measuring space complexity. I am learning to program in C++. Are there

Guava ImmutableMap has noticeably slower access than HashMap

*爱你&永不变心* 提交于 2019-12-03 06:30:38
问题 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

How do I accurately time how long it takes to call a function on the iPhone?

北战南征 提交于 2019-12-03 06:19:08
问题 I would like to know how long it's taking to send a message to an object with at least a 1ms accuracy. How do I do this? 回答1: You can use mach_absolute_time to measure in nanoseconds. #import <mach/mach_time.h> uint64_t startTime = 0; uint64_t endTime = 0; uint64_t elapsedTime = 0; uint64_t elapsedTimeNano = 0; mach_timebase_info_data_t timeBaseInfo; mach_timebase_info(&timeBaseInfo); startTime = mach_absolute_time(); //do something here endTime = mach_absolute_time(); elapsedTime = endTime -

How to calculate MIPS for an algorithm for ARM processor

依然范特西╮ 提交于 2019-12-03 06:18:28
问题 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,

Get local time in nanoseconds [duplicate]

人走茶凉 提交于 2019-12-03 05:08:56
问题 This question already has answers here : Closed 7 years ago . 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? 回答1: Yes, today most hardware supports this sort of resolution, and the C++ standard library has an API

Comparing times with sub-second accuracy

一世执手 提交于 2019-12-03 04:15:49
How can I get the number of milliseconds since epoch? Note that I want the actual milliseconds, not seconds multiplied by 1000. I am comparing times for stuff that takes less than a second and need millisecond accuracy. (I have looked at lots of answers and they all seem to have a *1000) I am comparing a time that I get in a POST request to the end time on the server. I just need the two times to be in the same format, whatever that is. I figured unix time would work since Javascript has a function to get that time.time() * 1000 will give you millisecond accuracy if possible. int(time.time() *

Benchmarking PHP page load times

爱⌒轻易说出口 提交于 2019-12-03 03:51:39
问题 How could I measure the time taken to load a page (with various different PHP statements)? Somewhat like the stats available here - http://talks.php.net/show/drupal08/24 回答1: The most simple too is Apache Bench (called ab ) , which is provided with Apache : It's a command-line tool That can send many requests, in parallel, to and URL And reports timings, errors, ... Seems to fit the kind of very simple reporting that's presented on your slide. (It does actually report more than that) If your