benchmarking

Java loop gets slower after some runs / JIT's fault?

ⅰ亾dé卋堺 提交于 2019-11-27 20:48:23
So I wanted to benchmark some basic java functionality to add some imformation to this question: What is the gain from declaring a method as static . I know writing benchmarks is sometimes not easy but what happens here I cannot explain. Please note that I'm not interessted in how to fix this but on why this happens* The Test class: public class TestPerformanceOfStaticVsDynamicCalls { private static final long RUNS = 1_000_000_000L; public static void main( String [] args ){ new TestPerformanceOfStaticVsDynamicCalls().run(); } private void run(){ long r=0; long start, end; for( int loop = 0;

Array vs Slice: accessing speed

微笑、不失礼 提交于 2019-11-27 20:44:12
问题 This question is about the speed of accessing elements of arrays and slices, not about the efficiency of passing them to functions as arguments. I would expect arrays to be faster than slices in most cases because a slice is a data structure describing a contiguous section of an array and so there may be an extra step involved when accessing elements of a slice (indirectly the elements of its underlying array). So I wrote a little test to benchmark a batch of simple operations. There are 4

get execution time in milliseconds in R

喜夏-厌秋 提交于 2019-11-27 20:07:01
I have read a solution to this using tic(), toc() functions tic <- function(gcFirst = TRUE, type=c("elapsed", "user.self", "sys.self")) { type <- match.arg(type) assign(".type", type, envir=baseenv()) if(gcFirst) gc(FALSE) tic <- proc.time()[type] assign(".tic", tic, envir=baseenv()) invisible(tic) } toc <- function() { type <- get(".type", envir=baseenv()) toc <- proc.time()[type] tic <- get(".tic", envir=baseenv()) print(toc - tic) invisible(toc) } tic(); -----code---- toc(); elapsed 0.15 But I would like to get a lot of precision in milliseconds? Also I was using this ptm <- proc.time() --

clearing a small integer array: memset vs. for loop

左心房为你撑大大i 提交于 2019-11-27 19:59:33
问题 There are two ways to zero out an integer/float array: memset(array, 0, sizeof(int)*arraysize); or: for (int i=0; i <arraysize; ++i) array[i]=0; obviously, memset is faster for large arraysize . However, at what point is the overhead of memset actually larger than the overhead of the for loop? For example, for an array of size 5 - which would be best? The first, the 2nd, or maybe even the un-rolled version: array[0] = 0; array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; 回答1: In all

How many hardware details can a Java Applet Discover?

淺唱寂寞╮ 提交于 2019-11-27 19:55:57
I'm writing a Java applet to run differently under different hardware. For instance if I know a computer has a large amount of RAM but a weak processor, I can alter the balance of some time-memory trade-offs. Being able to discover the exact make and model of the CPU on which the applet is running could be helpful. Having such information would allow me to benchmark my software against different systems and find bottlenecks. Generally what I'm looking for is: Number of cores and/or processors 32 bit vs 64 bit CPU CPU Cache line size Size of L1, L2, L3 cache Set associativity of cache Size of

C#: Is this benchmarking class accurate?

我们两清 提交于 2019-11-27 19:50:57
问题 I created a simple class to benchmark some methods of mine. But is it accurate? I am kind of new to benchmarking, timing, et cetera, so thought I could ask for some feedback here. Also, if it is good, maybe somebody else can make use of it as well :) public static class Benchmark { public static IEnumerable<long> This(Action subject) { var watch = new Stopwatch(); while (true) { watch.Reset(); watch.Start(); subject(); watch.Stop(); yield return watch.ElapsedTicks; } } } You can use it like

How to speed up matrix multiplication in C++?

空扰寡人 提交于 2019-11-27 19:49:46
I'm performing matrix multiplication with this simple algorithm. To be more flexible I used objects for the matricies which contain dynamicly created arrays. Comparing this solution to my first one with static arrays it is 4 times slower. What can I do to speed up the data access? I don't want to change the algorithm. matrix mult_std(matrix a, matrix b) { matrix c(a.dim(), false, false); for (int i = 0; i < a.dim(); i++) for (int j = 0; j < a.dim(); j++) { int sum = 0; for (int k = 0; k < a.dim(); k++) sum += a(i,k) * b(k,j); c(i,j) = sum; } return c; } EDIT I corrected my Question avove! I

Why does this delay-loop start to run faster after several iterations with no sleep?

浪尽此生 提交于 2019-11-27 18:26:38
Consider: #include <time.h> #include <unistd.h> #include <iostream> using namespace std; const int times = 1000; const int N = 100000; void run() { for (int j = 0; j < N; j++) { } } int main() { clock_t main_start = clock(); for (int i = 0; i < times; i++) { clock_t start = clock(); run(); cout << "cost: " << (clock() - start) / 1000.0 << " ms." << endl; //usleep(1000); } cout << "total cost: " << (clock() - main_start) / 1000.0 << " ms." << endl; } Here is the example code. In the first 26 iterations of the timing loop, the run function costs about 0.4 ms, but then the cost reduces to 0.2 ms.

Why push method is significantly slower than putting values via array indices in Javascript

夙愿已清 提交于 2019-11-27 17:48:23
问题 I pretty don't understand why this test : http://jsperf.com/push-method-vs-setting-via-key Shows that a.push(Math.random()); is over ten times slower than a[i] = Math.random(); Could you explain why this is the case ? What magic "push" do that make it so slow ? (or so slow compared to other valid method of doing that). EDIT NOTE: The push test is biased. I increase size of the array every iteration! Read carefully accepted answer! 回答1: Could you explain why this is the case? Because your test

Why is python so much slower on windows?

孤街醉人 提交于 2019-11-27 17:39:40
问题 I learned about pystones today and so I decided to see what my various environments were like. I ran pystones on my laptop that is running windows on the bare metal and got these results Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from test import pystone >>> for i in range(0,10): ... pystone.pystones() ... (1.636334799754252, 30556.094026423627) (2.1157907919853756, 23631