[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/1] qtest: pre-buffer hex nibs
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 1/1] qtest: pre-buffer hex nibs |
Date: |
Thu, 07 May 2015 14:21:02 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
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.
>
> This gives a moderate speed boost to memread() and memwrite() functions.
>
> Signed-off-by: John Snow <address@hidden>
> ---
> - qtest_send_prefix(chr);
> - qtest_send(chr, "OK 0x");
> + enc = g_malloc(2 * len + 1);
> for (i = 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 = 0; i < len; i++) {
const char digits[] = "0123456789abcdef";
enc[i * 2] = digits[data[i] >> 4];
enc[i * 2 + 1] = digits[data[i] & 0xf];
}
enc[len * 2] = '\0';
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature