📄 diskhashtest.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: DiskHashTest.java,v 1.7 2000/10/28 16:55:15 daniela Exp $package org.ozoneDB.DxLib.test;import java.lang.*;import java.util.*;import org.ozoneDB.DxLib.*;class DiskHashTest extends AbstractTest { public static void main( String[] args ) throws Exception { int n = Integer.valueOf( args[0] ).intValue(); int cacheBits = 8; int bufferSize = 4; System.out.println( n + " elements" ); DxDiskHashMap map = new DxDiskHashMap( "/tmp/diskhash/map", bufferSize, cacheBits, 8 ); // add long start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { map.addForKey( new Integer( i ), new Integer( i ) ); } System.out.println( "time (add): " + (System.currentTimeMillis() - start) ); // re-read (buffered) int nn = Math.min( (bufferSize - 2) * 256, n ); start = System.currentTimeMillis(); for (int i = 0; i < nn; i++) { Integer si = (Integer)map.elementForKey( new Integer( i ) ); if (!si.equals( new Integer( i ) )) { throw new RuntimeException( "corrupted" ); } } System.out.println( "time (re-read buffered: " + nn + "): " + (System.currentTimeMillis() - start) ); // re-read (buffered) start = System.currentTimeMillis(); for (int i = 0; i < nn; i++) { Integer si = (Integer)map.elementForKey( new Integer( i ) ); if (!si.equals( new Integer( i ) )) { throw new RuntimeException( "corrupted" ); } } System.out.println( "time (re-read buffered: " + nn + "): " + (System.currentTimeMillis() - start) ); // re-read start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { Integer si = (Integer)map.elementForKey( new Integer( i ) ); if (!si.equals( new Integer( i ) )) { throw new RuntimeException( "corrupted" ); } } System.out.println( "time (re-read): " + (System.currentTimeMillis() - start) ); // re-read start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { Integer si = (Integer)map.elementForKey( new Integer( i ) ); if (!si.equals( new Integer( i ) )) { throw new RuntimeException( "corrupted" ); } } System.out.println( "time (re-read): " + (System.currentTimeMillis() - start) ); // close start = System.currentTimeMillis(); map.close(); System.out.println( "time (close): " + (System.currentTimeMillis() - start) ); map.printStatistics(); // map.cleanFiles(); } public void stress( DxMap map ) { Random rand = new Random( System.currentTimeMillis() ); for (int j = 0; j < 10; j++) { double gaussian = rand.nextGaussian(); int EX = (int)(Math.abs( gaussian ) * 10000); System.out.println( "EX: " + EX ); int VAR = 1000; for (int i = 0; i < 100; i++) { int index = (int)(Math.abs( rand.nextGaussian() ) * VAR + EX); // System.out.println ("add: " + index); map.addForKey( new Integer( index ), new Integer( index ) ); } int hitCount = 0; for (int i = 0; i < 500; i++) { int index = (int)(Math.abs( rand.nextGaussian() ) * VAR + EX); // System.out.println ("add: " + index); if (map.elementForKey( new Integer( index ) ) != null) { hitCount++; } } System.out.println( "hit count:" + hitCount ); for (int i = 0; i < 500; i++) { int index = (int)(Math.abs( rand.nextGaussian() ) * VAR + EX); // System.out.println ("remove: " + index); map.removeForKey( new Integer( index ) ); } System.out.println( "count:" + map.count() ); } if (map instanceof DxDiskHashMap) { ((DxDiskHashMap)map).printStatistics(); ((DxDiskHashMap)map).cleanFiles(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -