A long history of language, the following do some IO experiment (traverse 9G files, bulk delete), as far as possible to use the facts to compare who superior who inferior. Operating system: Win7 64-bit, file package size: 9.68G.
First, language: C #
Development environment: vs 2013
Total lines of code: 43 rows
Time: 7 seconds
Code:
Using system;using system.collections.generic;using system.io;using system.linq;using System.Text;using System.threading.tasks;namespace batchdelete{class Program {static void Main (string[] args) { Input directory e:\tmp string path; Console.WriteLine ("Enter directory to clean up:"); Path = Console.ReadLine (); Start Chronograph Console.WriteLine ("Start Timing:" +datetime.now.tostring ("HH:mm:ss")); Loop through the matching lookup to remove the if (directory.exists (path)) {Console.Write ("deleting") first; foreach (String fileName in Directory.getfilesystementries (path)) {if (File.exists (File Name) && filename.contains ("Cachegrind.out")) {File.delete (fileName); }} Console.WriteLine (""); } else {Console.WriteLine ("The directory does not exist!"); } Chronograph end Console.WriteLine ("End timing:" + DateTime.Now.ToString ("HH:mm:ss")); Console.readkey (); } }}
Run:
Second, language: C + +
Development environment: vs 2013
Total lines of code: 50 rows
Time: 36 seconds
Code:
#include <iostream>#include<string>#include<Windows.h>#include<boost\filesystem\operations.hpp>#include<boost\filesystem\path.hpp>#include<boost\filesystem\convenience.hpp>#include<boost\algorithm\string.hpp>using namespacestd;intMainintargcChar*argv[]) { //Enter directory e:\tmp stringstrpath; cout<<"Enter the directory you want to clean up:"<<Endl; Getline (CIN, strpath); //Start TimingSYSTEMTIME Sys_time;//declaring VariablesGetlocaltime (&sys_time);//set the value of a variable to local timeprintf"Start timing:%02d:%02d:%02d\n", Sys_time.whour,sys_time.wminute,sys_time.wsecond); //Loop through match lookup and recycle delete namespaceFS =Boost::filesystem; FS::p Ath Full_path (Fs::initial_path ()); Full_path=fs::system_complete (fs::p Ath (strpath, fs::native)); if(Fs::exists (Full_path)) {cout<<"is deleting" ; FS::d irectory_iterator Item_begin (Full_path); FS::d Irectory_iterator item_end; for(; Item_begin! = Item_end; item_begin++) { if(!fs::is_directory (*Item_begin)) { if(Fs::exists (Item_begin->path ()) && Boost::contains (Item_begin->path ().string(),"Cachegrind.out") {fs::remove (Item_begin-path ()); } }} cout<<""<<Endl; } Else{cout<<"The directory does not exist!"<<Endl; } //End of timingGetlocaltime (&sys_time); printf ("Chronograph end:%02d:%02d:%02d\n", Sys_time.whour, Sys_time.wminute, Sys_time.wsecond); System ("Pause"); return 0;}
Run:
Third, language: PHP
Development environment: Phpstorm
Total lines of code: 32 rows
Time: 13 seconds
Code:
<?php/** * Created by Phpstorm. * User:administrator * date:16-1-29 * time: Morning 9:31 */date_default_timezone_set (' PRC ');//input Directory E:\tmp$path = ' e:\tmp ';//start Timing echo Date ("H:i:s", Time ()). ' <br/> ';//iterate through the matching lookup and then loop Delete if (Is_dir ($path)) { echo "is deleting"; $mydir = Dir ($path); while ($file = $mydir->read ()) { if (file_exists ("$path/$file") && Strpos ($file, ' cachegrind.out ') = = = 0) { unlink ("$path/$file");} } Echo ' <br/> ';} else{ echo "This directory does not exist!". ' <br/> ';} Timing ends Echo Date ("H:i:s", Time ()). ' <br/> ';
Run:
Iv. Language: Java
Development environment: Eclipse
Total lines of code: 43 rows
Time: 10 seconds
Code:
Package Com.yejing;import Java.io.file;import Java.text.simpledateformat;import java.util.date;import Java.util.scanner;public class Test {public static void main (string[] args) {Scanner s = new Scanner (system.in);//input Directory E: \tmpstring path = null; System.out.println ("Enter directory to clean up:");p ath = S.next ();//Start Timing date nowtime=new date (); SimpleDateFormat time=new SimpleDateFormat ("HH:mm:ss"); System.out.println ("Start chronograph:" + Time.format (nowtime)); Loop through the matching lookup to remove the file dir = new file (path), and if (Dir.exists ()) {System.out.print ("deleting"); file[] fs = Dir.listfiles (); for (int i=0;i<fs.length;i++) {if (!fs[i].isdirectory ()) {if (Fs[i].isfile () && FS [I].exists () && fs[i].getname (). Contains ("Cachegrind.out")) {Fs[i].delete ();}} } System.out.println ("");} ELSE{SYSTEM.OUT.PRINTLN ("The directory does not exist!");} Chronograph end Nowtime=new Date (); System.out.println ("Start chronograph:" + Time.format (nowtime)); }}
Run:
V. Language: Python 3.3.5
Development environment: IDLE
Total lines of code: 20 rows
Time: 10 seconds
Code:
#-*-Coding:utf-8-*- import datetimeimport OS # input Directory E:\tmppath = input ("Enter directory to clean up: \ n"); # Start time print ("Start timer:", datetime . DateTime.Now (). Strftime ('%h:%m:%s '); # iterate through the match lookup and then loop the delete if (path): print ("deleting"); For parent,dirnames,filenames in Os.walk (path): for filename in filenames: TargetFile = os.path.join (parent, FileName) if (Os.path.isfile (targetfile) and "Cachegrind.out" in TargetFile): os.remove (targetfile) Else: print ("The directory does not exist!"); # Time End Print ("End chronograph:", Datetime.datetime.now (). Strftime ('%h:%m:%s '));
Run:
Control Experiment (1)-Batch cleanup system temp file