Go_vs_java_ file read-write speed by line

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

1: Operating Environment Description:

go:1.0.3 64-bit

JDK:1.7_U9 64-bit

Operating system: Win7 64-bit, Thinkpad T410i,i3 M350,2.27ghz, dual core 4 thread, 8G RAM

Text files: UTF-8 plain text files, in units of behavior, file size 2.6G

Program target: Reads the file in the behavior unit and writes the read line to another new file.

2: Program Results

Java totaltime:96096 MS Client mode
Java totaltime:77595 MS Server mode
Go totaltime:75328 ms
The above results are for reference only ...

3: Test Code

Java code

Package Function.filehelper;import Java.io.bufferedreader;import Java.io.bufferedwriter;import Java.io.fileinputstream;import Java.io.fileoutputstream;import Java.io.inputstreamreader;import Java.io.outputstreamwriter;public class SingleFileMergeFilter3 {public String inFile = "D:/00/tk.txt";p ublic string Inencode = "UTF-8";p ublic string outFile = "D:/00/tk3.txt";p ublic string outencode = "UTF-8";p rivate fileinputstream fis;p Rivate inputstreamreader isr;private bufferedreader bfr;private fileoutputstream fos;private OutputStreamWriter OSW; Private BufferedWriter bwo;public void Dealbyline () throws Exception{this.fis = new FileInputStream (inFile); This.isr = NE W InputStreamReader (This.fis, inencode); this.bfr = new BufferedReader (THIS.ISR); This.fos = new FileOutputStream ( OutFile); this.osw = new OutputStreamWriter (This.fos, outencode); this.bwo = new BufferedWriter (THIS.OSW); long s = System.currenttimemillis (); String line = null;while (line = This.bfr.readLine ())! = null) {This.bwo.write (line + "\ r \ n");} This.bwo.flush (); Long e = System.currenttimemillis (); System.out.println ("TotalTime:" + (e-s)); This.bfr.close (); This.bwo.close ();} public static void Main (string[] args) throws Exception {new SingleFileMergeFilter3 (). Dealbyline ();}}

Go code
Package Mainimport ("Bufio" "FMT" "IO" "OS" "Time") Func main () {var inFile = "D:/00/tk.txt" var outFile = "D:/00/tk2.txt" fi, _ : = OS. Open (inFile) defer fi. Close () FO, _: = OS. Create (outFile) defer fo. Close () r: = Bufio. Newreader (FI) W: = Bufio. Newwriter (FO) var s = time. Now () var line stringfor {linebyte, _, Er3: = R.readline () if er3! = Nil && Er3 = io. EOF {break}line = string (linebyte) w.writestring (line + "\ r \ n")}w.flush () var e = time. Now () Fmt. Println ("TotalTime:", E.sub (s). nanoseconds ()/1000/1000)}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.