Java Vector API

Java Vector API as Matrix vs Java Matrix as primitives

Free Starter Classes MIT License

package data;

import java.util.Vector;

public class VectorMatrix<T> {
	private Vector<Vector<T>> matrix;
	
	public int getWidth() {
		return matrix.size();
	}
	
	public int getHeight() {
		return matrix.get(0).size();
	}	
	
	public VectorMatrix(int width, int height, T defaultValue) {
		matrix = new Vector<>(width);
		for (int i=0; i<width; i++) {
			matrix.add(i,new Vector<T>(height));
			for (int j=0; j<height; j++) {
				matrix.get(i).add(defaultValue);
			}
		}
	}
	
	public T getElement(int i, int j) {
		return matrix.get(i).get(j);
	}
	
	public void setElement(int i, int j, T element) {
		matrix.get(i).set(j, element);
	}
}

Preforms slower at least on my machine than

package data;

public class BooleanMatrix {
    boolean matrix[][];
	
	public int getWidth() {
		return matrix.length;
	}
	
	public int getHeight() {
		return matrix[0].length;
	}	
	
	public BooleanMatrix(int width, int height, boolean defaultValue) {
		matrix = new boolean[width][height];
	}
	
	public boolean getElement(int i, int j) {
		return matrix[i][j];
	}
	
	public void setElement(int i, int j, boolean element) {
		matrix[i][j]=element;
	}
}

Using it on a render app for an measuring time to render 30 frames, when I used two color images with primitives matrix I get around 600 ms. When I was using the Vector API I was getting around 4500 ms.

My comprehension there is potential for performance gains using Vector API yet I am not seeing them, seeing the opposite at least with a matrix of booleans.

https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html

Actually measuring Java Performance Gains could like be a lot easier, like an annotation @Performance

Here is a Free Starter Classes (that doesn’t use annotations)

package performance;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;

public class PerformanceUtil {
	private ArrayList<PerformanceReading> performanceReadings = new ArrayList<>();
	private boolean stopWatchStarted = false;
	public boolean isStopWatchStarted() {
		return stopWatchStarted;
	}

	private long startTime;
	private long endTime;
	private long recordedTime=0;
	private static PerformanceUtil instance;
	
	public static PerformanceUtil getInstance() {
		if (null == instance) {
			instance = new PerformanceUtil();
		}
		
		return instance;
	}
	
	private Instant start;
	private Instant stop;
	
	public void startInstant() {
		start = Instant.now();
	}
	
	public void stopInstant() {
		stop = Instant.now();
	}
	
	public long getInstantDifferenceMilliseconds() {
		return Duration.between(start, stop).toMillis();
	}
	
	public boolean start() {
		if (stopWatchStarted) {
			return false;
		} else {
			startTime=System.nanoTime();
			stopWatchStarted=true;
			return true;
		}
	}
	
	public boolean stop() {
		if (!stopWatchStarted) {
			return false;
		} else {
			endTime=System.nanoTime();
			stopWatchStarted=false;
			return true;
		}
	}
	
	public long getRunningTime() {
		long runningTime = System.nanoTime()-startTime;
		return runningTime;
	}
	
	public long getRecordedTime() {
		recordedTime=endTime-startTime;
		return recordedTime;
	}
	
	public int getRecordedTimeMilliseconds() {
		recordedTime=endTime-startTime;
		double milliseconds = recordedTime/1000000;
		return (int) milliseconds;
	}	
	
	public void clearPerformanceReadingsList() {
		performanceReadings = new ArrayList<>();		
	}
	
	public void addPerformanceReading(String performanceReadingName) {
		long recordedTime = getRecordedTime();
		PerformanceReading performanceReading = new PerformanceReading(recordedTime, performanceReadingName);
		performanceReadings.add(performanceReading);		
	}
	
	public PerformanceReading summarizePerformanceReadings(String readingName, ArrayList<PerformanceReading> readings) {
		long sum=0;
		for (int i=0; i<readings.size(); i++) {
			sum = readings.get(i).getNanoseconds();			
		}
		long average = sum/readings.size();
		
		return new PerformanceReading(average, readingName);
	}
	
	public ArrayList<PerformanceReading> getPerformanceReadings() {
		return performanceReadings;
	}
}

Have had issues with system nanoTime giving less than ideal results thus I added a the instant method which seems to give better values.

Seems like we should be getting much better performance given current machines.

Ideally heterogenous multiprocessing like OpenCL would be allowing me to use my other computers, devices and phones as extra processors.

CEO Partially enables Defense Lawyers resources that will be required to get them out of Jail? Maybe wiser not to partially limit.

Might need to be an interoperability commission, a standards board that requires a certain level of product from conglomerates

Published by techinfodebug

Flex and Java Developer, Christian, Art, Music, Video, and Vlogging

Leave a comment