相关疑难解决方法(0)

如何快速计算线?

我尝试了unxutils ' wc -l但它崩溃了1GB文件.我试过这个C#代码

long count = 0;
using (StreamReader r = new StreamReader(f))
{
    string line;
    while ((line = r.ReadLine()) != null)
    {
        count++;
    }
}

return count;
Run Code Online (Sandbox Code Playgroud)

它在4秒内读取500MB文件

var size = 256;
var bytes = new byte[size];
var count = 0;
byte query = Convert.ToByte('\n');
using (var stream = File.OpenRead(file))
{
    int many;
    do
    {
        many = stream.Read(bytes, 0, size);
        count += bytes.Where(a => a == query).Count();                    
    } while (many == size);
}
Run Code Online (Sandbox Code Playgroud)

在10秒内读取

var count …
Run Code Online (Sandbox Code Playgroud)

c# streamreader wc

30
推荐指数
2
解决办法
2万
查看次数

为什么Python httplib的块大小被硬编码为8192字节

我正在寻求快速流式下载 - >上传以通过HTTP将大型文件从一台服务器移动到另一台服务器.

在此期间,我注意到urllib3使用的httplib因此也是请求,似乎硬编码它从流中一次取出多少到8192字节

https://github.com/python/cpython/blob/28453feaa8d88bbcbf6d834b1d5ca396d17265f2/Lib/http/client.py#L970

为什么是这样?8192比其他尺寸有什么好处?

python http httplib

13
推荐指数
2
解决办法
726
查看次数

使用BinaryReader读取大文件(> 1 GB)时,最佳缓冲区大小是多少?

我正在阅读二进制文件,这是一个示例:

public static byte[] ReadFully(Stream input)
{
    byte[] buffer = new byte[16*1024];
    int read;
    while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
    {
        ......
    }

}
Run Code Online (Sandbox Code Playgroud)

显然缓冲区大小(16*1024)在性能方面有很大的作用.我读过它取决于I/O技术(SATA,SSD,SCSI)等)以及它上面存在文件的分区的片段大小(我们可以在格式化分区期间定义).

但问题: 是否有任何公式或最佳实践来定义缓冲区大小?现在,我正在根据反复试验来定义.

编辑: 我已经在我的服务器上测试了不同缓冲区大小的应用程序,并且我获得了4095*256*16(16 MB)的最佳性能!4096慢了4秒.

以下是一些非常有用的旧帖子,但我仍然无法得到原因:

.net c# windows filesystems performance

10
推荐指数
1
解决办法
9114
查看次数

4kb缓冲长度有什么特别之处?

在.NET中执行文件IO时,似乎95%的示例使用4096字节缓冲区.4kb缓冲长度有什么特别之处?或者它只是在for循环中使用i作为索引的约定?

.net io buffer

6
推荐指数
1
解决办法
713
查看次数

为什么Rijndael加密代码不适用于大文件?

我使用以下Rijndael代码进行多次加密.但为什么它不能加密4.2 GB的ISO文件?实际上我的电脑有16GB内存,不应该是内存问题.我使用Windows 7旗舰版.使用Visual Studio 2010(VB.NET项目)将代码编译为winform(.Net 4).

我已经检查过ISO文件是否正常,可以作为虚拟驱动器安装,甚至可以刻录到DVD ROM.所以它不是ISO文件问题.

我的问题:为什么以下代码无法加密大小为4.2GB的ISO文件?这是由Windows/.NET 4实现的限制引起的吗?

Private Sub DecryptData(inName As String, outName As String, rijnKey() As Byte, rijnIV() As Byte)

    'Create the file streams to handle the input and output files.
    Dim fin As New IO.FileStream(inName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
    Dim fout As New IO.FileStream(outName, System.IO.FileMode.OpenOrCreate,
       System.IO.FileAccess.Write)
    fout.SetLength(0)

    'Create variables to help with read and write.
    Dim bin(100) As Byte 'This is intermediate storage for the encryption.
    Dim rdlen As Long = 0 'This is the total number …
Run Code Online (Sandbox Code Playgroud)

.net vb.net rijndael

3
推荐指数
1
解决办法
710
查看次数

标签 统计

.net ×3

c# ×2

buffer ×1

filesystems ×1

http ×1

httplib ×1

io ×1

performance ×1

python ×1

rijndael ×1

streamreader ×1

vb.net ×1

wc ×1

windows ×1