edu.mines.jtk.bench.ArrayFileBench Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edu-mines-jtk Show documentation
Show all versions of edu-mines-jtk Show documentation
Java packages for science and engineering
The newest version!
/****************************************************************************
Copyright 2006, Colorado School of Mines and others.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/
package edu.mines.jtk.bench;
import java.io.*;
import java.nio.ByteOrder;
import edu.mines.jtk.io.*;
import static edu.mines.jtk.util.ArrayMath.*;
import edu.mines.jtk.util.Stopwatch;
/**
* Benchmark for {@link edu.mines.jtk.io.ArrayFile}.
* @author Dave Hale, Colorado School of Mines
* @version 2006.01.17
*/
public class ArrayFileBench {
public static void main(String[] args) {
benchEndian();
benchStream();
}
///////////////////////////////////////////////////////////////////////////
// private
private static void benchStream() {
try {
boolean[] b = {false,true};
for (boolean buffered:b) {
File file = File.createTempFile("junk","dat");
file.deleteOnExit();
//File file = new File("junk.dat");
benchStream(file,buffered);
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
private static void benchStream(File file, boolean buffered)
throws IOException
{
System.out.println("buffered="+buffered);
Stopwatch sw = new Stopwatch();
int nh = 60; // like a trace header
int na = 1000; // like trace samples
int[] h = randint(nh);
float[] a = randfloat(na);
double maxtime=60.0,s;
double mbytes = 4.0e-6*(nh+na);
long nw,nr,rate;
FileOutputStream fos = new FileOutputStream(file);
ArrayOutputStream aos = buffered ?
new ArrayOutputStream(new BufferedOutputStream(fos)) :
new ArrayOutputStream(fos);
sw.restart();
for (nw=0,s=0.0; sw.time()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy