• 拷贝与剪切的性能


    今天用程序复制图片,速度好慢

    A,同盘下剪切比复制快很多倍,原因是更改了文件的路径,也就是磁盘文件的分区表,而没有改动文件
    B,从移动磁盘复制或剪切到电脑,速度取决于移动磁盘,从实际看,是复制更快点
    C,数据从电脑复制或剪切到移动磁盘,速度都一样,对于移动磁盘都是写入,而且通常速度都达到饱和(USB2.0下)
    D,数据从电脑的D盘复制或剪切到E盘或者其他盘上,是复制更快点,减少磁头工作量就是增快速度!

    核心就是谁的 磁头工作,以及磁头的工作量

    Copy 与 Move 同盘符下 测试
    class Program
        {
            static void Main(string[] args)
            {
                CopyToTest();
                MoveToTest();
                Console.ReadLine();
            }
    
            static string[] GetImgFiles() 
            {
                string path = @"";
                return Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);
            }
    
            static string[] GetImgFiles1()
            {
                string path = @"D:\TIANDITU\DATA\POIDATA\大众点评网\川菜\bjc";
                return Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);
            }
    
            static void MoveToTest()
            {
                string root = @"";
                DateTime dtStart = DateTime.Now;
                string[] arr = GetImgFiles1();
                int counter = 0;
                foreach (string item in arr)
                {
                    string target = Path.Combine(root, counter.ToString() + ".jpg");
                    File.Move(item, target);
                    counter++;
                }
                DateTime dtEnd = DateTime.Now;
                TimeSpan ts = dtEnd - dtStart;
                Console.WriteLine("statistics for move");
                Console.WriteLine(ts.TotalSeconds);
                Console.WriteLine(ts.TotalMinutes);
            }
    
    
            static void CopyToTest() 
            {
                string root=@"D:\TIANDITU\DATA\POIDATA\大众点评网\川菜\bjc";
                DateTime dtStart = DateTime.Now;
                string[] arr = GetImgFiles();
                int counter = 0;
                foreach (string item in arr)
                {
                    string target = Path.Combine(root, counter.ToString()+".jpg");
                    File.Copy(item, target);
                    counter++;
                }
                DateTime dtEnd = DateTime.Now;
                TimeSpan ts = dtEnd - dtStart;
                Console.WriteLine("statistics for copy");
                Console.WriteLine(ts.TotalSeconds);
                Console.WriteLine(ts.TotalMinutes);
            }
        }

    测试结果
    statistics for copy
    113.78125
    1.89635416666667
    statistics for move
    13.84375
    0.230729166666667

    Move 比 copy 快了 10倍左右


  • 相关阅读:
    通向KDE4之路(七):文档反省器Okular和Ligature
    KDE言语绑定──KDEBindings
    KDEEdu(教诲性质软件)引见
    KDEMultimedia(KDE多媒体东西)引见
    KDESDK(KDE斥地工具)引见
    通向KDE4之路(十五):Konsole年夜整修
    企业信息化规划http://www.blogcn.com/User/fieldnet/index.html
    写在博客一周年
    Delphi 的内存操作函数(3): 给结构体指针分配内存
    在 Delphi 2009 中, for in 循环都能用在什么地方?
  • 原文地址:https://www.cnblogs.com/i80386/p/2514960.html
Copyright © 2020-2023  润新知