Skip to content

performance-data-collection/algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

algorithms

Algorithms used in this project

Data source

  • Random numbers

For random numbers we use https://www.randomizer.org/

Research Randomizer is a free service offered by Social Psychology Network for researchers, students, and others interested in generating sets of random numbers. See below for some random information about the site.

As with most computer-based "random number generators," this program is best described as a "pseudo-random number generator" because the numbers are generated by use of a complex algorithm (seeded by the computer's clock) that gives the appearance of randomness.

  • Ordered numbers

An array of ordered numbers are generated using the function described below:

	int[] createOrderedIntArray(int numberOfElements) {
		int[] array = new int[numberOfElements];
		for (int i = 0; i < numberOfElements; i++)
			array[i] = i;
		return array;
	}

Iterations Vs. Streams

The following examples of streams vs iterations were published by Angelika Langer[0] and by Nicolai Parlog[1].

[0] https://jaxenter.com/java-performance-tutorial-how-fast-are-the-java-8-streams-118830.html [1] https://blog.codefx.org/java/stream-performance/

Find the maximum value in an array (or iterations comparizon)

This is a very simple iteration using an array of random numbers. In this specific example we will measure the inpact of boxing and unboxing.

Java 7:

int m = Integer.MIN_VALUE;
for (int i = 0; i < intArray.length; i++)
	if (intArray[i] > m)
		m = intArray[i];

Java 8/9:

// Max delegates to 'reduce'
Arrays.stream(intArray).max();

Find the maximum value in a List

Java 7

int m = Integer.MIN_VALUE;
for (int i : myList)
     if (i>m) m=i;
int m = Integer.MIN_VALUE;
for (int i = 0; i < intList.size(); i++)
	if (intList.get(i) > m)
		m = intList.get(i);

Java 8/9

intList.stream().max(Math::max);

Comparison of more complex algorithms

Mandelbrot Set

Definition: http://mathworld.wolfram.com/MandelbrotSet.html

The idea behind this test is to render the fractal set using the different implementations in java and check the impact of the move to use a stream.

Java 7 algorithm: https://github.com/Byron/benchmarksgame-cvs-mirror/blob/25f5255653e2c02672e2da4e1fc120318f053764/bench/mandelbrot/mandelbrot.java-2.java

      Crb=new double[N+7]; Cib=new double[N+7];
      double invN=2.0/N; for(int i=0;i<N;i++){ Cib[i]=i*invN-1.0; Crb[i]=i*invN-1.5; }
      yCt=new AtomicInteger();
      out=new byte[N][(N+7)/8];

      Thread[] pool=new Thread[2*Runtime.getRuntime().availableProcessors()];
      for (int i=0;i<pool.length;i++)
         pool[i]=new Thread(){
            public void run() {
                int y; while((y=yCt.getAndIncrement())<out.length) putLine(y,out[y]);
            }
         };
      for (Thread t:pool) t.start();
      for (Thread t:pool) t.join();

Java 8/9 algorithm: https://github.com/Byron/benchmarksgame-cvs-mirror/blob/c01d6969d1e4b5101ba6dcb7e8c3f794454bd682/bench/mandelbrot/mandelbrot.java-4.java

	  IntStream.range(0,N).parallel().forEach(y -> {
		  double Ciby = y*invN-1.0;
		  int offset = y*lineLen;
		  for(int x=0; x<lineLen; x++)
			  data[offset+x] = getByte(Crb, Ciby, x*8);
	  });

About

Multiple algorithms to be used during the performance tests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages