From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user Subject: Re: string-for-each vs. for-each+string->list performance Date: Sun, 07 Jun 2020 15:50:48 +0200 Message-ID: <7377875a-507d-471e-866b-0f505517ff82@www.fastmail.com> References: Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="91690"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.3.0-dev0-519-g0f677ba-fm-20200601.001-g0f677ba6 To: =?UTF-8?Q?Aleix_Conchillo_Flaqu=C3=A9?= , guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Jun 07 15:51:23 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhvhq-000NjO-SU for guile-user@m.gmane-mx.org; Sun, 07 Jun 2020 15:51:23 +0200 Original-Received: from localhost ([::1]:37430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhvhp-0001Ni-TP for guile-user@m.gmane-mx.org; Sun, 07 Jun 2020 09:51:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhvhh-0001NX-9v for guile-user@gnu.org; Sun, 07 Jun 2020 09:51:13 -0400 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:46319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhvhf-0006WW-60 for guile-user@gnu.org; Sun, 07 Jun 2020 09:51:13 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5B05F5C008D; Sun, 7 Jun 2020 09:51:09 -0400 (EDT) Original-Received: from imap1 ([10.202.2.51]) by compute4.internal (MEProxy); Sun, 07 Jun 2020 09:51:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.se; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type:content-transfer-encoding; s=fm3; bh=gJ1fV UurRZl3aIUnnzIdi5Vtt46KykSrzlE9VLNm9Bw=; b=mzeMoyYZ5ON7izYZx06G9 ugNCy8bmBtoht0VFigHDpS/iW3CeUk1AF9iMTGrJYdg6Mc1PFJ6VrwBMWF/YSh/v DrKMsuNAV9AlM6XXvD/BFN5lfORJanmjcC2volZmsVOBWzwpZHqkPGOE4RffC4gM v5tADtoL3thtGmwLXHgbq9167XCcR5e5KQhhNXyBj+wifp9igTNNIRy8aFcJe+TP Bds+HACalIs1E0157tILUzsBlJduR3DON7//YLm/WVtFzqyt2eG/KLLcjyyr2uTS EdY1xbryFPKzGmgnxaXaeYRcvzX0/tYzdbxg8J98SYdb6Gp6Vscx24BR+BwUdIPL Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=gJ1fVUurRZl3aIUnnzIdi5Vtt46KykSrzlE9VLNm9 Bw=; b=VacVvsvV1krgXJupuFwDsuppQ8vF9O0TefEgxzB/zSMz6HyOzkgVKmXD9 T3pu0D+QTW0yHwZz3zM5wIduJ6yidJYCnb0E2POFzfA47o3nkNsnQSHgKxH++Mt1 mpQzgNCgMKz7f7Jeus62jsa/3n0JM2JLs7TLr3eC05ic12XWHmgRSrNu2zEBbHJl k/m27I7Rr50hYRmGpYsfjhp3/FTlwaFNmAKDDoRTt/vZAtYeyZAHaxYxQqWWnwNK t8lBtQmiDnlaKI4hyuVcH1QBOzkL9mI4aV1YOORhh3Qv2sFSRypzNtoDWM9KxhQ0 SPqqNcTesPXrgZ2b3zBIL8Ury2Owg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudegledgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpefnihhn uhhspgeujhpnrhhnshhtrghmuceolhhinhhushdrihhnthgvrhhnvghtsehfrghsthhmrg hilhdrshgvqeenucggtffrrghtthgvrhhnpedtfedvtdefvdefuedukeeluddtgfdtgeeh geeljeeuvedvteekgfehjefgvdeggeenucffohhmrghinhepghhnuhdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlihhnuhhsrdhi nhhtvghrnhgvthesfhgrshhtmhgrihhlrdhsvg X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1E6F5C200A4; Sun, 7 Jun 2020 09:51:09 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: Received-SPF: pass client-ip=66.111.4.28; envelope-from=linus.internet@fastmail.se; helo=out4-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/07 09:51:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16562 Archived-At: You can cut another 15-ish % from that loop by making an inline loop, bt= w (let loop ((pos 0)) (when (< pos (string-length str)) ... (loop (1+ pos))) I have been looking at the disassembly, even for simpler cases, but I ha= ven't been able to understand enough of it.=20 BTW: string-for-each is in the default environment, and is probably the = same as the srfi-13 C implementation. --=20 Linus Bj=C3=B6rnstam On Sun, 7 Jun 2020, at 08:27, Aleix Conchillo Flaqu=C3=A9 wrote: > Hi, >=20 > in the latest guile-json, 4.1.0. I changed some code to use > for-each+string->list. The performance seemed nice and I released it. >=20 > Christopher Lam pointed out that I could have used string-for-each ins= tead. > I made the change but the performance degraded a lot: >=20 > string-for-each: >=20 > scheme@(json parser)> ,t (->bool (scm->json-string json)) > $19 =3D #t > ;; 17.909537s real time, 18.063382s run time. 0.207281s spent in GC. >=20 > vs >=20 > for-each + string->list: >=20 > scheme@(json parser)> ,t (->bool (scm->json-string json)) > $20 =3D #t > ;; 2.998381s real time, 3.319349s run time. 0.471969s spent in GC. >=20 > string-for-each is implemented in scheme here, if Im not wrong: >=20 > http://git.savannah.gnu.org/cgit/guile.git/tree/module/rnrs/base.scm#n= 89 >=20 > string->list and for-each would use C. >=20 > Is that huge gap expected? >=20 > This is with Guile 3.0.2. >=20 > Best, >=20 > Aleix >