标签:public new 堆内存 creat nbsp erro xss string 适合
方法区配置import java.nio.ByteBuffer;
/**
* Created by xxd on 2017/4/2.
*/
public class AccessDirectBuffer {
public void directAccess(){
long startTime = System.currentTimeMillis();
ByteBuffer bf = ByteBuffer.allocateDirect(500);
for (int i=0;i<100000;i++){
for (int j=0;j<99;j++){
bf.putInt(j);
}
bf.flip();
for (int j=0;j<99;j++){
bf.getInt();
}
bf.clear();
}
long endTime = System.currentTimeMillis();
System.out.println("testDirectWrite:"+(endTime - startTime));
}
public void bufferAccess(){
long startTime = System.currentTimeMillis();
ByteBuffer bf = ByteBuffer.allocate(500);
for (int i=0;i<100000;i++){
for (int j=0;j<99;j++){
bf.putInt(j);
}
bf.flip();
for (int j=0;j<99;j++){
bf.getInt();
}
bf.clear();
}
long endTime = System.currentTimeMillis();
System.out.println("testBufferWrite:"+(endTime - startTime));
}
public static void main(String[] args){
AccessDirectBuffer alloc = new AccessDirectBuffer();
alloc.bufferAccess();
alloc.directAccess();
alloc.bufferAccess();
alloc.directAccess();
}
}
import java.nio.ByteBuffer;
/**
* Created by xxd on 2017/4/2.
*/
public class AllocDirectBuffer {
public void directAllocate(){
long startTime = System.currentTimeMillis();
for (int i=0;i<200000;i++){
ByteBuffer bf = ByteBuffer.allocateDirect(1000);
}
long endTime = System.currentTimeMillis();
System.out.println("directAllocate : "+(endTime-startTime));
}
public void bufferAllocate(){
long startTime = System.currentTimeMillis();
for (int i=0;i<200000;i++){
ByteBuffer bf = ByteBuffer.allocate(1000);
}
long endTime = System.currentTimeMillis();
System.out.println("bufferAllocate : "+(endTime-startTime));
}
public static void main(String[] args){
AllocDirectBuffer adb = new AllocDirectBuffer();
adb.bufferAllocate();
adb.directAllocate();
adb.bufferAllocate();
adb.directAllocate();
}
}
标签:public new 堆内存 creat nbsp erro xss string 适合
原文地址:http://www.cnblogs.com/xxdfly/p/4aaf80c81243f9225c725b52ad376d32.html