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)}