reddit discussion on replacing Python in 0install

Denis Koroskin 2korden at gmail.com
Fri Jun 14 01:11:17 PDT 2013


On Wednesday, 12 June 2013 at 06:48:48 UTC, Walter Bright wrote:
> On 6/11/2013 10:15 PM, deadalnix wrote:
>> On Wednesday, 12 June 2013 at 04:23:39 UTC, Walter Bright 
>> wrote:
>>> I don't agree. Buffering is often done on page size 
>>> boundaries - throwing out
>>> a random number of characters and then flushing will get it 
>>> all wonky.
>>
>> You clearly missed something in the discussion here. The 
>> proposal is to flush
>> once at first use, so an Exception is thrown. Nothing change 
>> after that first
>> flush at initialization, other flushes stay where they are.
>
> Not at all. A flush forces a write to the disk - that's the 
> point of it. Disks are not at all well tuned to writing a few 
> bytes, they like to be written in aligned blocks of block 
> sizes, and the I/O subsystem is designed for that.
>
> This is why stdout has a flag in it saying if it is a "block 
> oriented" or "character oriented" device. It makes a big 
> difference. This proposal attempts to treat a block device like 
> a character device. It will work, but it will perform poorly.
>
> P.S. I've written device drivers for disks.
>
> P.P.S. The solution is simple, as I said earlier. Just do a 
> flush after main() exits. It happens anyway - done by the C 
> stdio subsystem - I just propose doing it in the D code before 
> it hands things back to the C runtime. This will entail no 
> performance degradation.

How about we test it before making any claims?

I wrote a simple test program that writes 4gigs of '!' to stdout, 
and measured it in 2 ways:

time ./a.out > /dev/null
time ./a.out > file.txt

Here are the test runs (a warmup followed by 3 runs of each):

Output to /dev/null W/O FLUSH
real	0m0.188s 0m0.186s 0m0.190s
user	0m0.166s 0m0.165s 0m0.168s
sys	0m0.021s 0m0.020s 0m0.021s

/dev/null WITH FLUSH
real	0m0.168s 0m0.166s 0m0.163s
user	0m0.145s 0m0.144s 0m0.142s
sys	0m0.022s 0m0.021s 0m0.021s

Output to file.txt W/O FLUSH
real	0m10.131s 0m11.766s 0m9.900s
user	0m0.444s 0m0.443s 0m0.451s
sys	0m5.352s 0m5.324s 0m5.308s

real	0m9.474s 0m9.971s 0m10.115s
user	0m0.233s 0m0.241s 0m0.233s
sys	0m5.588s 0m5.616s 0m5.591s

Does it look like it's slower? To me it looks like it's actually 
FASTER with a flush, although I don't know why. Try it yourself. 
The code that I tested with is below (apologies for using C).

#include <stdio.h>
#include <string.h>

int main()
{
     char buffer[4096];
     memset(buffer, '!', 4096);
     fwrite(buffer, 1, 100, stdout);
     //fflush(stdout);
     for (int i = 0; i < 1024*1024; ++i) {
       fwrite(buffer, 1, 4096, stdout);
     }
     return 0;
}



More information about the Digitalmars-d mailing list