From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqSNa-0002MP-OH for qemu-devel@nongnu.org; Thu, 07 May 2015 16:26:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqSNX-0007hw-Hw for qemu-devel@nongnu.org; Thu, 07 May 2015 16:26:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37951) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqSNX-0007hn-D7 for qemu-devel@nongnu.org; Thu, 07 May 2015 16:26:43 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 05C4E8E6EC for ; Thu, 7 May 2015 20:26:42 +0000 (UTC) Message-ID: <554BCA81.6030302@redhat.com> Date: Thu, 07 May 2015 16:26:41 -0400 From: John Snow MIME-Version: 1.0 References: <1431021095-7558-1-git-send-email-jsnow@redhat.com> <1431021095-7558-2-git-send-email-jsnow@redhat.com> <554BC92E.1090401@redhat.com> In-Reply-To: <554BC92E.1090401@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Eric Blake , qemu-devel@nongnu.org Cc: armbru@redhat.com On 05/07/2015 04:21 PM, Eric Blake wrote: > On 05/07/2015 11:51 AM, John Snow wrote: >> Instead of converting each byte one-at-a-time and then sending >> each byte 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. >>=20 >> Signed-off-by: John Snow --- >=20 >> - 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]); >=20 > Making a function call to sprintf() has a lot of overhead. Isn't > it even faster to open-code the conversion, something like: >=20 "Maybe." > 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 In practice I didn't see a statistical difference between my previous nib-encoding function on my machine and this sprintf version, so I opted not to add any new bit twiddling. The bulk of the savings comes from not engaging the full socket send for two bytes over and over and over again. --js