Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Jun 2017 09:37:40 -0700
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        Pietro Cerutti <gahr@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r319897 - head/usr.bin/yes
Message-ID:  <e54ef1a5-affd-076a-d5b3-43904263f328@FreeBSD.org>
In-Reply-To: <201706131235.v5DCZ1aR077437@repo.freebsd.org>
References:  <201706131235.v5DCZ1aR077437@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--G9ANrb6WwfJ1XQQi8UuiLlBP5PfoW50QW
Content-Type: multipart/mixed; boundary="pL7vgUXcv4VdRfEKgBqD352ivvo7hXnN6";
 protected-headers="v1"
From: Bryan Drewery <bdrewery@FreeBSD.org>
To: Pietro Cerutti <gahr@FreeBSD.org>, src-committers@freebsd.org,
 svn-src-all@freebsd.org, svn-src-head@freebsd.org
Message-ID: <e54ef1a5-affd-076a-d5b3-43904263f328@FreeBSD.org>
Subject: Re: svn commit: r319897 - head/usr.bin/yes
References: <201706131235.v5DCZ1aR077437@repo.freebsd.org>
In-Reply-To: <201706131235.v5DCZ1aR077437@repo.freebsd.org>

--pL7vgUXcv4VdRfEKgBqD352ivvo7hXnN6
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable

On 6/13/2017 5:35 AM, Pietro Cerutti wrote:
> Author: gahr (ports committer)
> Date: Tue Jun 13 12:35:01 2017
> New Revision: 319897
> URL: https://svnweb.freebsd.org/changeset/base/319897
>=20
> Log:
>   Improve yes' throughput
>  =20
>   On my system, this brings up the throughput from ~20 to ~600 MiB/s.
>  =20
>   Inspired by: https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu=
_yes_so_fast/
>  =20
>   Reviewed by:	cognet
>   Approved by:	cognet
>=20
> Modified:
>   head/usr.bin/yes/yes.c
>=20
> Modified: head/usr.bin/yes/yes.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/yes/yes.c	Tue Jun 13 12:07:18 2017	(r319896)
> +++ head/usr.bin/yes/yes.c	Tue Jun 13 12:35:01 2017	(r319897)
> @@ -44,20 +44,42 @@ static const char rcsid[] =3D "$FreeBSD$";
>  #include <capsicum_helpers.h>
>  #include <err.h>
>  #include <stdio.h>
> +#include <string.h>
> +#include <unistd.h>
> =20
>  int
>  main(int argc, char **argv)
>  {
> +	char buf[8192];

8192 feels arbitrary but it has a purpose.  Shouldn't it be based on
PAGE_SIZE or something?

> +	char y[2] =3D { 'y', '\n' };
> +	char * exp =3D y;
> +	size_t buflen =3D 0;
> +	size_t explen =3D sizeof(y);

More style bugs here

> =20
>  	if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno !=3D ENOSYS))=

>  		err(1, "capsicum");
> =20
>  	if (argc > 1)
> -		while (puts(argv[1]) !=3D EOF)
> -			;
> -	else
> -		while (puts("y") !=3D EOF)
> -			;
> +	{
> +		exp =3D argv[1];
> +		explen =3D strlen(exp) + 1;
> +		exp[explen - 1] =3D '\n';
> +	}
> +
> +	if (explen <=3D sizeof(buf))
> +	{
> +		while (buflen < sizeof(buf) - explen)
> +		{
> +			memcpy(buf + buflen, exp, explen);
> +			buflen +=3D explen;
> +		}
> +		exp =3D buf;
> +		explen =3D buflen;
> +	}
> +
> +	while (write(STDOUT_FILENO, exp, explen) > 0)
> +		;
> +
>  	err(1, "stdout");
>  	/*NOTREACHED*/
>  }
>=20


--=20
Regards,
Bryan Drewery


--pL7vgUXcv4VdRfEKgBqD352ivvo7hXnN6--

--G9ANrb6WwfJ1XQQi8UuiLlBP5PfoW50QW
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJZQBTbAAoJEDXXcbtuRpfPE+sH/0v+v1ZatSCHsuIQHQQjfUEZ
5xXgWjASh686BsjcU/K5An0Gmg/WeKk0Jkk0CUUWW7omZ2Ufobq5vnzzdriqqwgt
eeL9gr8sXFmiRzhGzrCAYK7lRRrj+bEM1f/Tj5IInO+1hDm7r0VQP5pHnyFRmmtR
hIjb8Lq5s4PZa2VpK09euj47VlB3wloylm686vt+sLgB6TUcaNXcLuWpkP5BgbvR
I+7aLut5S02Lewt+kU+jpmFhVaT/c3kHJBJbXGr1ZBTTgvKSB4dru/Yg8K0/SDG3
bWgYTRj3299le2SSFLbCJeY3IUqTHr6QjEuzfn1M2Sa2Wko6DuYdW3zxxHmMZlQ=
=FS2V
-----END PGP SIGNATURE-----

--G9ANrb6WwfJ1XQQi8UuiLlBP5PfoW50QW--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e54ef1a5-affd-076a-d5b3-43904263f328>