From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqSI8-0001A1-Ty for qemu-devel@nongnu.org; Thu, 07 May 2015 16:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqSI5-00063n-OF for qemu-devel@nongnu.org; Thu, 07 May 2015 16:21:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqSI5-00063d-H4 for qemu-devel@nongnu.org; Thu, 07 May 2015 16:21:05 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t47KL3hH018594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 7 May 2015 16:21:04 -0400 Message-ID: <554BC92E.1090401@redhat.com> Date: Thu, 07 May 2015 14:21:02 -0600 From: Eric Blake MIME-Version: 1.0 References: <1431021095-7558-1-git-send-email-jsnow@redhat.com> <1431021095-7558-2-git-send-email-jsnow@redhat.com> In-Reply-To: <1431021095-7558-2-git-send-email-jsnow@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fXEfNgSFowW5cAtAOQhiOh02EpQ4bUd1S" Subject: Re: [Qemu-devel] [PATCH 1/1] qtest: pre-buffer hex nibs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow , qemu-devel@nongnu.org Cc: armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --fXEfNgSFowW5cAtAOQhiOh02EpQ4bUd1S Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/07/2015 11:51 AM, John Snow wrote: > Instead of converting each byte one-at-a-time and then sending each byt= e > over the wire, use sprintf() to pre-compute all of the hex nibs into a > single buffer, then send the entire buffer all at once. >=20 > This gives a moderate speed boost to memread() and memwrite() functions= =2E >=20 > Signed-off-by: John Snow > --- > - qtest_send_prefix(chr); > - qtest_send(chr, "OK 0x"); > + enc =3D g_malloc(2 * len + 1); > for (i =3D 0; i < len; i++) { > - qtest_sendf(chr, "%02x", data[i]); > + sprintf(&enc[i * 2], "%02x", data[i]); Making a function call to sprintf() has a lot of overhead. Isn't it even faster to open-code the conversion, something like: for (i =3D 0; i < len; i++) { const char digits[] =3D "0123456789abcdef"; enc[i * 2] =3D digits[data[i] >> 4]; enc[i * 2 + 1] =3D digits[data[i] & 0xf]; } enc[len * 2] =3D '\0'; --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --fXEfNgSFowW5cAtAOQhiOh02EpQ4bUd1S 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 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVS8kuAAoJEKeha0olJ0NqKr0H/34TIZWPGvUGrTQ6wWbBNihb gg7SRObCIUDjQWbJF//Osf/xBmnt07lVuPz6LVwTCyNXUoPm2SfWWrbUXw+ngWBy 2ouT4gRXwq6btTIqhUVLl41R7XdvExK54aWPngpilRjBQR6+H1uIcF+BS1bqlLbY n4srwbYbN/9qQxOf0lyLnJVXjtaMXyVVvr+3z0WvjvEBq6tYCARfKY93/jIG6Asg Uaqce6tCsfMJDAUsW07vaZPgfy3ZD0tQfmdHw5NCbRIJQRe4xV9n/i0uNB0pCIq1 4UHTUi3XL8m4CtrswvLZKQixygzslRcnxDBj7lSz4XXaVCMcx0qhAVB4EVVGVqo= =3cHz -----END PGP SIGNATURE----- --fXEfNgSFowW5cAtAOQhiOh02EpQ4bUd1S--