Compare experiment (1)-batch cleanup of temporary system files and compare experiment cleanup _ PHP Tutorial

Source: Internet
Author: User
Compare experiment (1)-Clear temporary system files in batches and compare experiment files. Comparison Experiment (1)-batch cleanup of temporary system files, Comparison Experiment to clear language competition for a long time, below do some IO experiments (traverse more than 9 GB files, batch delete ), try to use facts to compare experiments (1)-Clean up temporary system files in batches and compare experiments

Language competition has been around for a long time. I will do some I/O experiments (traverse more than 9 GB files and delete them in batches) below to compare who is better and who is worse with the facts. OS: win7 64-bit, file package size: 9.68 GB.

I. language: C #

Development Environment: V. S. 2013

Total number of lines of code: 43

Time consumed: 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 the directory to be cleared:"); path = Console. readLine (); // start the timer Console. writeLine ("Start time:" + DateTime. now. toString ("HH: mm: ss"); // traverse and match to find and recycle and delete if (Directory. exists (path )) {Console. write ("deleting"); foreach (string fileName in Directory. getFileSystemEntries (path) {if (File. exists (fileName) & fileName. contains ("cachegrind. out ") {File. delete (fileName) ;}} Console. writeLine ("");} else {Console. writeLine ("this directory does not exist! ");} // Time end Console. writeLine ("End time:" + DateTime. now. toString ("HH: mm: ss"); Console. readKey ();}}}

Run:

2. language: C/C ++

Development Environment: V. S. 2013

Total number of lines of code: 50

Time consumed: 36 seconds

Code:

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         Using namespace std; int main (int argc, char * argv []) {// input directory e: \ tmp string strPath; cout <"Enter the directory to be cleared: "<endl; getline (cin, strPath); // start timing SYSTEMTIME sys_time; // declare the variable GetLocalTime (& sys_time ); // Set the variable value to the local time printf ("Start time: % 02d: % 02d: % 02d \ n", sys_time.wHour, sys_time.wMinute, sys_time.wSecond ); // traverse and match search first, find and recycle and delete namespace fs = boost: filesystem; fs: path full_path (fs: initial_path (); full_path = fs:: System_complete (fs: path (strPath, fs: native); if (fs: exists (full_path) {cout <"deleting"; fs :: directory_iterator item_begin (full_path); fs: directory_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 <"this directory does not exist! "<Endl ;}// time end GetLocalTime (& sys_time); printf (" Time End: % 02d: % 02d: % 02d \ n ", sys_time.wHour, sys_time.wMinute, sys_time.wSecond); system ("pause"); return 0 ;}
       
      
     
    
   
  
 

Run:

III. language: PHP

Development Environment: Phpstorm

Total number of lines of code: 32

Time consumed: 13 seconds

Code:

 '; // Search, Find, recycle, delete, if (is_dir ($ path) {echo "deleting"; $ mydir = dir ($ path ); while ($ file = $ mydir-> read () {if (file_exists ("$ path/$ file") & strpos ($ file, 'cachegrind. out') = 0) {unlink ("$ path/$ file") ;}} echo'
';} Else {echo "this directory does not exist! ".'
';} // Time End echo date ("H: I: s", time ()).'
';

Run:

4. language: Java

Development Environment: eclipse

Total number of lines of code: 43

Time consumed: 10 seconds

Code:

Package com. yejing; import java. io. file; import java. text. simpleDateFormat; import java. util. date; import java. util. role; public class Test {public static void main (String [] args) {s = new role (System. in); // input directory e: \ tmpString path = null; System. out. println ("Enter the directory to be cleaned:"); path = s. next (); // start timing Date nowTime = new Date (); SimpleDateFormat time = new SimpleDateFormat ("HH: mm: ss"); System. out. println ("start timing:" + time. format (nowTime); // first traverse and match to find and recycle delete File dir = new File (path); if (dir. exists () {System. out. print ("deleting"); File [] fs = dir. listFiles (); for (int I = 0; I
 
  

Run:

V. language: Python 3.3.5

Development Environment: IDLE

Total number of lines of code: 20

Time consumed: 10 seconds

Code:

#-*-Coding: UTF-8-*-import datetimeimport OS # input directory e: \ tmppath = input ("input directory to be cleaned: \ n "); # Start Time print ("Start time:", datetime. datetime. now (). strftime ('% H: % M: % S'); # traverse and match to find and recycle and delete if (OS. path. exists (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. r Emove (targetFile) else: print ("this directory does not exist! "); # Print (" End time: ", datetime. datetime. now (). strftime ('% H: % M: % S '));

Run:

Batch (1)-batch cleanup of temporary system files. it has been a long time to compete against the language in the experiment. below we will do some IO experiments (traverse more than 9 GB files and delete them in batches ), try to use facts for comparison...

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.