Your script is incorrect.

$ dd if=/dev/zero bs=1 | ./nread 1234567 | wc -c
0+2411 records in
0+2411 records out
2411 bytes transferred in 0.038 secs (62579 bytes/sec)
135+0 records in
135+0 records out
135 bytes transferred in 0.001 secs (126148 bytes/sec)
    2546

$ man dd
...
     count=n  Copy only n input blocks.
...

These are input, not output blocks.


On Wed, Jun 20, 2018 at 11:42 PM, Tomasz Rola <rto...@ceti.pl> wrote:
> On Wed, Jun 20, 2018 at 08:20:16PM +0200, Maximilian Pichler wrote:
>> On Wed, Jun 20, 2018 at 7:17 PM, Tomasz Rola <rto...@ceti.pl> wrote:
>> > But seriously: man sh.
>>
>> Are you saying there is a shell built-in that does this? If so, which one?
>
> =>  (591 13):    cat nread
> #!/bin/sh
>
> # nread n - read up to n bytes from stdio, put them on to stdout
>
> N=$1
>
> dd bs=512 count=$((N / 512))
> dd bs=1 count=$((N % 512))
>
> =>  (591 14):   md5sum <nread
> 9c6d3e6aa2b11f6351290fc4f770bf44  -
>
> =>  (591 15):  chmod a+x nread
>
> =>  (591 16):   cat HUGE | /usr/bin/time ./nread 1234567 | wc -c
> 2411+0 records in
> 2411+0 records out
> 1234432 bytes (1.2 MB) copied, 0.0122527 s, 101 MB/s
> 135+0 records in
> 135+0 records out
> 135 bytes (135 B) copied, 0.000620305 s, 218 kB/s
> 0.00user 0.01system 0:00.02elapsed 57%CPU (0avgtext+0avgdata 768maxresident)k
> 0inputs+0outputs (0major+731minor)pagefaults 0swaps
> 1234567
>
> Total time is well below 1s. If you want faster, then you have to
> write it in C or assembly.
>
> --
> Regards,
> Tomasz Rola
>
> --
> ** A C programmer asked whether computer had Buddha's nature.      **
> ** As the answer, master did "rm -rif" on the programmer's home    **
> ** directory. And then the C programmer became enlightened...      **
> **                                                                 **
> ** Tomasz Rola          mailto:tomasz_r...@bigfoot.com             **
>

Reply via email to