如何加载大文件Hex Parall [英] How Do I Load Big File Hex Parall

查看:160
本文介绍了如何加载大文件Hex Parall的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我想加载像这样的快速大文件十六进制

下载hex。 rar - 38.3 KB 此文件有(69,632字节)

HexCounter

加载100万个十六进制鳕鱼的快速方法是什么?

* - 用记事本打开hex文件+(是一行)

* -last测试速度1.3125S(i3-3240 cpu @ 3.40Hz)

* -sort == false

hi i want load quickly big file hex like this
Download hex.rar - 38.3 KB this file have(69,632 byte)
HexCounter
what fast way to load 1 million hex cod?
*-open hex file with notepad+ (is one line)
*-last test speed 1.3125S with(i3-3240 cpu @ 3.40Hz)
*-sort==false

private void Load_file(string Address_file,List<String> add,bool sort)
    {
        FileStream magic = new FileStream(Address_file,FileMode.Open,FileAccess.Read);
        BinaryReader magic2 = new BinaryReader(magic);
        int _length = (int) magic.Length;
        for (int i = 0; i <= _length - 2; i++)
        {
             // 3 way i test it but?
            //add.Items.Add(cp[i].ToString() + cp[i+1].ToString());  //(char)
            // add.Items.Add(Convert.ToChar(magic2.Read()).ToString());
            //add.Add(Convert.ToChar(magic2.Read()).ToString() + Convert.ToChar(magic2.PeekChar()));
            add.Add((char)(magic2.Read()) + Convert.ToChar(magic2.PeekChar()).ToString());
              i++;
          }

        if (sort==true)
        {
            add.Sorted();
        }
    }



加载文件我使用此void


for load file i use this void

private void button2_Click(object sender, EventArgs e)
  {
      //open folder dilog
      ofd.Title = "Hex";
      ofd.Filter = "Text Normal|*.txt|Text INF|*.inf";
      if (ofd.ShowDialog() != DialogResult.Cancel)
      {
          Benchmark.Start();
          Load_file(ofd.FileName, list, false);  //set adress
          Benchmark.End();
          double seconds = Benchmark.GetSeconds();
          MessageBox.Show(seconds.ToString());

      }
  }





i使用此课程测试速度

class Benchmark
{
    private static DateTime startDate = DateTime.MinValue;
    private static DateTime endDate = DateTime.MinValue;

    public static TimeSpan Span { get { return endDate.Subtract(startDate); } }

    public static void Start() { startDate = DateTime.Now; }

    public static void End() { endDate = DateTime.Now; }

    public static double GetSeconds()
    {
        if (endDate == DateTime.MinValue) return 0.0;
        else return Span.TotalSeconds;
    }
}

推荐答案

首先,你不需要发明自己的class:有一个Stopwatch类作为System.Diagnostics命名空间的一部分,它可以做到这一点,但更好,并且具有更高的精度: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v = vs.110)的.aspx [ ^ ]



我的系统执行此操作:

First off, you don't need to invent your own class: there is a Stopwatch class as part of the System.Diagnostics namespace which does that, but better, and with a higher precision: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx[^]

And my system does this:
byte[] data = File.ReadAllBytes(@"D:\Temp\Output.bin");



,大约15毫秒,这是一个3.5 MB的测试文件,位于你正在使用的低得多的规格PC上。

你看到的缓慢不是读:它是将数据加载到列表框中。



您是否真的希望您的用户在一百万个小列表框中读取一兆字节的数据?因为如果我是你的用户之一,我就会追捕你并向你抗议......:笑:



我想你想认真重新考虑你的用户界面,而不是抱怨它缺乏速度!


in ~15 milliseconds, and that's a 3.5 MB test file on a much lower spec PC that you are using.
The slowness you are seeing is not the read: it's the load of the data into your listbox.

Are you seriously expecting your users to read a megabyte of data in one million little list box entries? Because if I was one of your users, I'd hunt you down and remonstrate with you...:laugh:

I think you want to seriously reconsider your UI, rather than complain about it's lack of speed!


        private void Load_file(string Address_file, List<string> add, bool sort)
        {
            byte[] data = File.ReadAllBytes(Address_file);
            int _length = (int)data.Length;
            for (int i = 0; i <= _length - 2; i++)
            {
                add.Add((data[i]) + (data[i+1]).ToString());
                  i++;  
              }
        }
</string>





读取2,042,098字节0.5秒



read 2,042,098 byte in 0.5s


这篇关于如何加载大文件Hex Parall的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆