all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs development discussions <emacs-devel@gnu.org>
Subject: Re: [RFC] temporary Lisp_Strings
Date: Tue, 02 Sep 2014 19:13:15 +0400	[thread overview]
Message-ID: <5405DE8B.4050201@yandex.ru> (raw)
In-Reply-To: <jwvppfeqg8e.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]

On 09/02/2014 06:00 PM, Stefan Monnier wrote:

> Have you made some preliminary measurements (on microbenchmarks) to try
> and see how much speed up we might gain?  Given the cost of strlen and
> parse_str_as_multibyte, I'd expect that the best-case benefit might turn
> out to be rather small.

For the moment, I don't have an idea how to benchmark parse_str_as_multibyte
in "near-to-real-use" conditions.  But I guess that we can have some gain
for "simple" (short, especially short unibyte) strings. That guess is based
on the following results (note ~3x speedup in strcpy/strcat workload):

$ gcc -Wall -O2 -o t-alloca t-alloca.c t-use.c
$
$ /usr/bin/time ./t-alloca 100 100
Use malloc for allocation and sprintf for workload
2.23user 0.00system 0:02.23elapsed 100%CPU (0avgtext+0avgdata 1440maxresident)k
0inputs+0outputs (0major+59minor)pagefaults 0swaps
$
$ /usr/bin/time ./t-alloca 100 100 x
Use alloca for allocation and sprintf for workload
1.85user 0.00system 0:01.85elapsed 99%CPU (0avgtext+0avgdata 1436maxresident)k
0inputs+0outputs (0major+59minor)pagefaults 0swaps
$
$ gcc -DFAST -Wall -O2 -o t-alloca t-alloca.c t-use.c
$
$ /usr/bin/time ./t-alloca 100 100
Use malloc for allocation and strcpy/strcat for workload
0.56user 0.00system 0:00.56elapsed 99%CPU (0avgtext+0avgdata 1440maxresident)k
0inputs+0outputs (0major+59minor)pagefaults 0swaps
$
$ /usr/bin/time ./t-alloca 100 100 x
Use alloca for allocation and strcpy/strcat for workload
0.20user 0.00system 0:00.20elapsed 100%CPU (0avgtext+0avgdata 1440maxresident)k
0inputs+0outputs (0major+60minor)pagefaults 0swaps

Dmitry


[-- Attachment #2: t-alloca.c --]
[-- Type: text/x-csrc, Size: 874 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef FAST
#define FUNCNAME "strcpy/strcat"
#else
#define FUNCNAME "sprintf"
#endif

extern void use_with_malloc (char *, int, char *, int);
extern void use_with_alloca (char *, int, char *, int);

int
main (int argc, char *argv[])
{
  char *p1, *p2;
  int i, len1, len2;

  if (argc >= 3)
    {
      len1 = atoi (argv[1]);
      len2 = atoi (argv[2]);

      p1 = malloc (len1 + 1);
      memset (p1, 'a', len1);
      p1[len1] = '\0';

      p2 = malloc (len2 + 1);
      memset (p1, 'b', len2);
      p2[len2] = '\0';

      printf ("Use %s for allocation and %s for workload\n",
	      (argc == 3) ? "malloc" : "alloca", FUNCNAME);

      for (i = 0; i < 10000000; i++)
	{
	  if (argc == 3)
	    use_with_malloc (p1, len1, p2, len2);
	  else
	    use_with_alloca (p1, len1, p2, len2);
	}
    }
  return 0;
}

[-- Attachment #3: t-use.c --]
[-- Type: text/x-csrc, Size: 499 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *ptr;

void
use_with_malloc (char *p, int plen, char *q, int qlen)
{
  ptr = malloc (plen + qlen + 1);
#ifdef FAST
  strcpy (ptr, p);
  strcat (ptr, q);
#else
  sprintf (ptr, "%s%s", p, q);
#endif
  (void) ptr;
  free (ptr);
}

void
use_with_alloca (char *p, int plen, char *q, int qlen)
{
  ptr = alloca (plen + qlen + 1);
#ifdef FAST
  strcpy (ptr, p);
  strcat (ptr, q);
#else
  sprintf (ptr, "%s%s", p, q);
#endif
  (void) ptr;
}

  reply	other threads:[~2014-09-02 15:13 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-02 12:55 [RFC] temporary Lisp_Strings Dmitry Antipov
2014-09-02 13:21 ` Andreas Schwab
2014-09-02 13:47   ` Dmitry Antipov
2014-09-02 14:14     ` Andreas Schwab
2014-09-02 15:00     ` Eli Zaretskii
2014-09-02 14:00 ` Stefan Monnier
2014-09-02 15:13   ` Dmitry Antipov [this message]
2014-09-02 17:32     ` Stefan Monnier
2014-09-03 10:23       ` Benchmarking temporary Lisp objects [Was: Re: [RFC] temporary Lisp_Strings] Dmitry Antipov
2014-09-03 13:14         ` Stefan Monnier
2014-09-03 14:39         ` Paul Eggert
2014-09-03 15:39           ` Dmitry Antipov
2014-09-03 16:42             ` Paul Eggert
2014-09-03 17:47               ` Stefan Monnier
2014-09-03 18:00                 ` Paul Eggert
2014-09-04  4:59               ` Dmitry Antipov
2014-09-04  5:13                 ` Paul Eggert
2014-09-04  5:51                   ` Dmitry Antipov
2014-09-04  6:45                     ` Paul Eggert
2014-09-04 13:11                     ` Stefan Monnier
2014-09-04 13:37                       ` Dmitry Antipov
2014-09-04 14:46                         ` Dmitry Antipov
2014-09-04 16:03                           ` Paul Eggert
2014-09-05  4:00                             ` Dmitry Antipov
2014-09-05  4:24                               ` Stefan Monnier
2014-09-05  9:28                                 ` Dmitry Antipov
2014-09-05  7:15                               ` Paul Eggert
2014-09-05  9:16                                 ` Dmitry Antipov
2014-09-05 14:35                                   ` Paul Eggert
2014-09-05 15:35                                 ` Stefan Monnier
2014-09-08 10:33                                   ` Dmitry Antipov
2014-09-08 12:01                                     ` Dmitry Antipov
2014-09-08 13:30                                       ` Stefan Monnier
2014-09-08 12:44                                     ` Stefan Monnier
2014-09-08 13:30                                       ` Stefan Monnier
2014-09-02 14:37 ` [RFC] temporary Lisp_Strings Paul Eggert
2014-09-02 15:24   ` Dmitry Antipov
2014-09-02 15:28   ` Dmitry Antipov
  -- strict thread matches above, loose matches on Subject: below --
2014-09-02 12:56 Dmitry Antipov

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=5405DE8B.4050201@yandex.ru \
    --to=dmantipov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.