日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
JavaNIO性能測(cè)試

時(shí)間(ms) 文件大小 (byte)
Buffer(byte) 434 603900
10000 0 0
1000 0 46
100 0 188
50 0 281
5 0 2406
1 47 12000

java 代碼:

 
 
  1. package com;      
  2.      
  3. import java.io.File;      
  4. import java.io.FileInputStream;      
  5. import java.io.FileOutputStream;      
  6. import java.io.IOException;      
  7. import java.nio.ByteBuffer;      
  8. import java.nio.channels.FileChannel;      
  9.      
  10. import junit.framework.TestCase;      
  11.      
  12. /**     
  13.  * NIO read write test     
  14.  *      
  15.  * @author wutao     
  16.  *      
  17.  */     
  18. public class NioDemo extends TestCase {      
  19.      
  20.     public void testRead() throws IOException {      
  21.      
  22.         int[] sizes = { 10000, 1000, 100, 50, 5, 1 };      
  23.      
  24.         // Arrays.sort(sizes);      
  25.      
  26.         System.out.println(new File("text.txt").length());      
  27.      
  28.         for (int i = 0; i < sizes.length; i++) {      
  29.      
  30.             int size = sizes[i];      
  31.      
  32.             FileInputStream fins = new FileInputStream("text.txt");      
  33.      
  34.             FileChannel fc = fins.getChannel();      
  35.      
  36.             if (!new File("text2.txt").exists()) {      
  37.                 new File("text2.txt").createNewFile();      
  38.             }      
  39.             ByteBuffer buffer = ByteBuffer.allocate(size);      
  40.      
  41.             FileOutputStream fouts = new FileOutputStream("text2.txt");      
  42.             FileChannel fc2 = fouts.getChannel();      
  43.      
  44.             long start = System.currentTimeMillis();      
  45.      
  46.             while (true) {      
  47.                 buffer.clear();      
  48.                 int r = fc.read(buffer);      
  49.                 if (r == -1) {      
  50.                     break;      
  51.                 }      
  52.                 buffer.flip();      
  53.                 fc2.write(buffer);      
  54.             }      
  55.      
  56.             long end = System.currentTimeMillis();      
  57.      
  58.             System.out.println("---------" + size + "---------");      
  59.             System.out.println(end - start);      
  60.             fc.close();      
  61.             fc2.close();      
  62.             fins.close();      
  63.             fouts.close();      
  64.         }      
  65.     }      
  66. }     
 
 
  1. Java? I/O, 2nd Edition  
  2. By Elliotte Rusty Harold   
  3. ...............................................   
  4. Publisher: O'Reilly   
  5. Pub Date: May 2006   
  6. Print ISBN-10: 0-596-52750-0   
  7. Print ISBN-13: 978-0-59-652750-1   
  8. Pages: 726  
 
 
  1. import java.io.*;     
  2. import java.nio.*;     
  3. import java.nio.channels.*;     
  4. public class NIOCopier {     
  5.   public static void main(String[] args) throws IOException {     
  6.     FileInputStream inFile = new FileInputStream(args[0]);     
  7.     FileOutputStream outFile = new FileOutputStream(args[1]);     
  8.     FileChannel inChannel = inFile.getChannel( );     
  9.     FileChannel outChannel = outFile.getChannel( );     
  10.     for (ByteBuffer buffer = ByteBuffer.allocate(1024*1024);     
  11.     inChannel.read(buffer) != -1;     
  12.     buffer.clear( )) {     
  13.       buffer.flip( );     
  14.       while (buffer.hasRemaining( )) outChannel.write(buffer);     
  15.     }     
  16.     inChannel.close( );     
  17.     outChannel.close( );     
  18.   }     
  19. }     

In a very unscientific test, copying one large (4.3-GB) file on one platform (a dual 2.5-GHz PowerMac G5 running Mac OS X 10.4.1) using traditional I/O with buffered streams and an 8192-byte buffer took 305 seconds. Expanding and reducing the buffer size didn't shift the overall numbers more than 5% and if anything tended to increase the time to copy. (Using a one-megabyte buffer like Example 14-1's actually increased the time to over 23 minutes.) Using new I/O as implemented in Example 14-1 was about 16% faster, at 255 seconds. A straight Finder copy took 197 seconds. Using the Unix cp command actually took 312 seconds, so the Finder is doing some surprising optimizations under the hood.

原文鏈接:http://wutaoo.iteye.com/blog/94666


網(wǎng)頁題目:JavaNIO性能測(cè)試
文章網(wǎng)址:http://www.dlmjj.cn/article/cdicjhg.html