benchmarking

Why is 2 * (i * i) faster than 2 * i * i in Java?

半腔热情 提交于 2019-11-28 13:06:58
问题 The following Java program takes on average between 0.50 secs and 0.55 secs to run: public static void main(String[] args) { long startTime = System.nanoTime(); int n = 0; for (int i = 0; i < 1000000000; i++) { n += 2 * (i * i); } System.out.println((double) (System.nanoTime() - startTime) / 1000000000 + " s"); System.out.println("n = " + n); } If I replace 2 * (i * i) with 2 * i * i , it takes between 0.60 and 0.65 secs to run. How come? I ran each version of the program 15 times,

Comprehensive vector vs linked list benchmark for randomized insertions/deletions

自作多情 提交于 2019-11-28 12:27:34
So I am aware of this question, and others on SO that deal with issue, but most of those deal with the complexities of the data structures (just to copy here, linked this theoretically has O( I understand the complexities would seem to indicate that a list would be better, but I am more concerned with the real world performance. Note: This question was inspired by slides 45 and 46 of Bjarne Stroustrup's presentation at Going Native 2012 where he talks about how processor caching and locality of reference really help with vectors, but not at all (or enough) with lists. Question: Is there a good

“No matching benchmarks” when running JMH from main in eclipse

会有一股神秘感。 提交于 2019-11-28 11:07:46
I wanted to try out the new feature of JMH by running it as Java Application in eclipse. I imported and built jmh-samples project. Compiled classes ended in /jmh-samples/target/generated-sources/annotations, there are several JARs in /target/ and running microbenchmarks.jar from command line works as usual. However when I execute main I always get No matching benchmarks. Miss-spelled regexp? Any ideas? I am using version 0.3 jmh-dev@ is a better way to communicate this with the developers. Few things to try: Hijacking Main is probably not a good idea. Use Java API instead, like this sample .

Why is local variable access faster than class member access in Python?

久未见 提交于 2019-11-28 10:59:46
While trying to tackle a more complex problem, I came to compare access speed to local variable vs member variables. Here a test program: #!/usr/bin/env python MAX=40000000 class StressTestMember(object): def __init__(self): self.m = 0 def do_work(self): self.m += 1 self.m *= 2 class StressTestLocal(object): def __init__(self): pass def do_work(self): m = 0 m += 1 m *= 2 # LOCAL access test for i in range(MAX): StressTestLocal().do_work() # MEMBER access test for i in range(MAX): StressTestMember().do_work() I know it might look like a bad idea to instantiate StressTestMember and

Is Intel's timestamp reading asm code example using two more registers than are necessary?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 10:11:40
I'm looking into measuring benchmark performance using the time-stamp register (TSR) found in x86 CPUs. It's a useful register, since it measures in a monotonic unit of time which is immune to the clock speed changing. Very cool. Here is an Intel document showing asm snippets for reliably benchmarking using the TSR, including using cpuid for pipeline synchronisation. See page 16: http://www.intel.com/content/www/us/en/embedded/training/ia-32-ia-64-benchmark-code-execution-paper.html To read the start time, it says (I annotated a bit): __asm volatile ( "cpuid\n\t" // writes e[abcd]x "rdtsc\n\t"

Benchmarking affected by VCL

邮差的信 提交于 2019-11-28 09:59:31
问题 Today I ported my old memory benchmark from Borland C++ builder 5.0 to BDS2006 Turbo C++ and found out weird thing. exe from BCB5 runs OK and stable exe from BDS2006 measure OK only before main Form is started (inside its constructor) and if the benchmark is started again after main form is Activated or even after any VCL component change (for example Caption of main form) then the speed of benchmark thread is strongly affected. After some research I found out that: Does not mater if test is

Python Numpy Data Types Performance

爱⌒轻易说出口 提交于 2019-11-28 09:41:29
So I did some testing and got odd results. Code: import numpy as np import timeit setup = """ import numpy as np A = np.ones((1000,1000,3), dtype=datatype) """ datatypes = "np.uint8", "np.uint16", "np.uint32", "np.uint64", "np.float16", "np.float32", "np.float64" stmt1 = """ A = A * 255 A = A / 255 A = A - 1 A = A + 1 """ #~ np.uint8 : 1.04969205993 #~ np.uint16 : 1.19391073202 #~ np.uint32 : 1.37279821351 #~ np.uint64 : 2.99286961148 #~ np.float16 : 9.62375889588 #~ np.float32 : 0.884994368045 #~ np.float64 : 0.920502625252 stmt2 = """ A *= 255 A /= 255 A -= 1 A += 1 """ #~ np.uint8 : 0

How to measure Disk Speed in Java for Benchmarking

好久不见. 提交于 2019-11-28 08:21:23
问题 I would like to know how can you measure disk speed using Java API. Random read,sequential read and Random and sequential write. If someone thinks it's not a real question. Please explain so before closing it. Thanks 回答1: You can take a look at a disk utility I wrote in java. It may not be super fancy but it works. https://sourceforge.net/projects/jdiskmark/ Here is a snippet of the write measurement code: try (RandomAccessFile rAccFile = new RandomAccessFile(testFile,mode)) { for (int b=0; b

Benchmarking inside Java code

一世执手 提交于 2019-11-28 08:20:46
I have been looking into benchmarking lately, I have always been interested in logging program data etc. I was interested in knowing if we can implement our own memory usage code and implement our own time consumption code efficently inside our program. I know how to check long it takes for a code to run: public static void main(String[]args){ long start = System.currentTimeMillis(); // code System.out.println(System.currentTimeMillis() - start); } I also looked into Robust Java benchmarking, Part 1: Issues , this tutorial is very comprehensive. Displays the negative effects of System

What's the best way to benchmark programs in Windows?

末鹿安然 提交于 2019-11-28 07:50:28
I need to do some performance benchmarks on .NET programs (C#) in Windows, but I haven't done benchmarking much in the Windows world. I've looked into using the Windows 2000/XP Performance monitor with custom counters for this, but I don't think this is quite what I want. Are there any good system facilities for this in Windows XP, or do I need to just use System.Diagnostics.Stopwatch [edit] and write text logs for manual interpretation, or is there something else? Edit: is there anything beyond System.Diagnostics.Stopwatch ? For micro-benchmarking I really like MeasureIt (can be downloaded