成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Java NIO性能測試

開發 后端
本文介紹了有關Java NIO的性能測試。

時間(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 = { 1000010001005051 };      
  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

責任編輯:林師授 來源: wutao8818的博客
相關推薦

2011-12-13 09:12:34

JavaNIO

2011-03-11 09:51:47

Java NIO

2023-07-12 08:24:19

Java NIO通道

2011-12-15 13:28:57

2011-03-15 16:34:36

Iptables性能

2009-11-30 09:40:23

Java 7 NIO2HTTP Server

2011-12-15 09:40:06

Javanio

2022-01-10 23:39:18

Java測試開發

2011-12-07 14:57:44

JavaNIO

2011-12-15 11:19:08

JavaNIO

2020-05-18 07:00:00

性能測試壓力測試負載測試

2011-06-08 16:59:04

性能測試載測試壓力測試

2009-09-22 17:41:07

Hibernate性能

2011-12-15 10:10:33

Javanio

2011-12-15 10:43:20

JavaNIO

2022-02-22 08:00:48

JavaNIOBuffer

2023-07-28 08:23:05

選擇器Java NIO

2010-01-28 09:55:05

性能優化

2015-01-06 09:59:03

2011-12-07 14:41:51

JavaNIO
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人精品一区二区三区中文字幕 | 国产香蕉视频在线播放 | 亚洲精品福利视频 | 国产在线观看网站 | 国产在线不卡 | 国产精品久久久久久久7电影 | 午夜影院网站 | 亚洲一区在线日韩在线深爱 | 日韩国产精品一区二区三区 | 久久久久久蜜桃一区二区 | 亚洲一区二区三区在线 | 久久久久久久久蜜桃 | 成人精品国产一区二区4080 | 欧美极品少妇xxxxⅹ免费视频 | 美女三区 | 国产成人99久久亚洲综合精品 | 国产偷久久一级精品60部 | 亚洲欧美中文日韩在线 | 国产婷婷色综合av蜜臀av | 91电影院| 毛片一级片 | 国产精品一区二区三区在线 | 精品免费 | 亚洲福利一区二区 | 一区久久 | 日韩欧美一区二区三区四区 | 亚洲一区三区在线观看 | 国产精品久久a | 免费观看一级特黄欧美大片 | 一区二区三区四区毛片 | 久久国产精品一区二区三区 | 亚洲精品99久久久久久 | 超碰97免费在线 | 日韩成人久久 | 精品三区 | 日韩最新网站 | 精品久久国产老人久久综合 | 国产在线精品一区 | 成人一区av偷拍 | 欧美激情精品久久久久久变态 | 欧美白人做受xxxx视频 |