'How can I read data faster?
Hmmm... its kinda challenging to find a method for reading/writing data faster enough to get ACCEPTED in this problem ( https://www.spoj.pl/problems/INTEST/ ) using F#.
My code ( http://paste.ubuntu.com/548748/ ) gets TLE...
Any ideas how to speed up data reading?
Solution 1:[1]
I don't actually know, but I would guess that reading a since character at a time is bad, and you should read e.g. 4k into a buffer at a time and then process the buffer.
Solution 2:[2]
let buf =
let raw = System.Console.OpenStandardInput()
let bytebuf = new System.IO.BufferedStream(raw)
new System.IO.StreamReader(bytebuf)
buf.Read() // retrieves a single character as an int from the buffer
buf.ReadLine() // retrieves a whole line from the buffer
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brian |
| Solution 2 | Markus Jarderot |
