qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/1] qtest: pre-buffer hex nibs
Date: Thu, 07 May 2015 16:26:41 -0400	[thread overview]
Message-ID: <554BCA81.6030302@redhat.com> (raw)
In-Reply-To: <554BC92E.1090401@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.
>> 
>> This gives a moderate speed boost to memread() and memwrite()
>> functions.
>> 
>> Signed-off-by: John Snow <jsnow@redhat.com> ---
> 
>> -        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:
> 

"Maybe."

> 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';
> 

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

  reply	other threads:[~2015-05-07 20:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-07 17:51 [Qemu-devel] [PATCH 0/1] qtest: hex nib buffering John Snow
2015-05-07 17:51 ` [Qemu-devel] [PATCH 1/1] qtest: pre-buffer hex nibs John Snow
2015-05-07 20:21   ` Eric Blake
2015-05-07 20:26     ` John Snow [this message]
2015-05-08 17:15   ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554BCA81.6030302@redhat.com \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).