From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Antipov Newsgroups: gmane.emacs.devel Subject: Re: [RFC] temporary Lisp_Strings Date: Tue, 02 Sep 2014 19:13:15 +0400 Message-ID: <5405DE8B.4050201@yandex.ru> References: <5405BE5D.1090003@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080606090503070002020808" X-Trace: ger.gmane.org 1409671216 16244 80.91.229.3 (2 Sep 2014 15:20:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Sep 2014 15:20:16 +0000 (UTC) Cc: Emacs development discussions To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 02 17:20:10 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XOpsO-0002Aj-Il for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 17:20:08 +0200 Original-Received: from localhost ([::1]:38742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOpsO-0008KV-54 for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 11:20:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOpm1-0007sB-2Q for emacs-devel@gnu.org; Tue, 02 Sep 2014 11:13:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOpls-0002wf-GD for emacs-devel@gnu.org; Tue, 02 Sep 2014 11:13:33 -0400 Original-Received: from forward2p.cmail.yandex.net ([77.88.31.17]:48182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOpls-0002tK-0j for emacs-devel@gnu.org; Tue, 02 Sep 2014 11:13:24 -0400 Original-Received: from smtp19.mail.yandex.net (smtp19.mail.yandex.net [95.108.252.19]) by forward2p.cmail.yandex.net (Yandex) with ESMTP id 12AA212BA; Tue, 2 Sep 2014 19:13:22 +0400 (MSK) Original-Received: from smtp19.mail.yandex.net (localhost [127.0.0.1]) by smtp19.mail.yandex.net (Yandex) with ESMTP id 4D74DBE0FE2; Tue, 2 Sep 2014 19:13:17 +0400 (MSK) Original-Received: from unknown (unknown [37.139.80.10]) by smtp19.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id dQA6HaVFPQ-DFUCqTDF; Tue, 2 Sep 2014 19:13:15 +0400 (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) X-Yandex-Uniq: 79d91d66-cae1-46fe-b02a-56fef93701f6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1409670795; bh=LCh7q4nrqNsXBcPi3BxGktR9FtO08gHSzaMsVr2+Fx8=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type; b=rGM4VjcK/zukslGbYqugkNaFoWqt70YdLMj7UcXWd4vlzQlp1N+WNxLFKjwAmrFfB 6M76dt3ff9lbqvoOis/lgBv49GrHbesaL4o27mN9CHkCWzhvdf8x8M+aRgWhGuP4jH UKFBDNn0gQlN/ceETGEwXuZir/SFoklWRsNGHR1U= Authentication-Results: smtp19.mail.yandex.net; dkim=pass header.i=@yandex.ru User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 77.88.31.17 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:173955 Archived-At: This is a multi-part message in MIME format. --------------080606090503070002020808 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------080606090503070002020808 Content-Type: text/x-csrc; name="t-alloca.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="t-alloca.c" #include #include #include #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; } --------------080606090503070002020808 Content-Type: text/x-csrc; name="t-use.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="t-use.c" #include #include #include 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; } --------------080606090503070002020808--