Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Created January 21, 2020 01:49
Show Gist options
  • Save hyrmn/17289a5454ff28bfd084643c80ba3f6c to your computer and use it in GitHub Desktop.
Save hyrmn/17289a5454ff28bfd084643c80ba3f6c to your computer and use it in GitHub Desktop.
netcore 3.1. hardcoded to the location of a 1.6gb text file
class Program
{
static void Main(string[] args)
{
var count = 0;
using var reader = File.OpenText(@"C:\code\go\src\github.com\hyrmn\lc\pkg\lc\testdata\bigsum.txt");
var buffer = new Span<char>(new char[1024]);
int readLength;
while ((readLength = reader.Read(buffer)) != 0)
{
var position = 0;
while(true)
{
var slice = buffer.Slice(position, readLength - position);
var idxOf = slice.IndexOf('\n');
if (idxOf == -1)
{
break;
}
count++;
position += idxOf + 1;
}
}
Console.WriteLine(count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment