From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: Extremly slow for format & string-join Date: Mon, 01 Apr 2013 13:13:20 +0800 Organization: HFG Message-ID: <1364793200.4639.10.camel@Renee-desktop.suse> References: <1364788801.4639.6.camel@Renee-desktop.suse> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1364793221 13854 80.91.229.3 (1 Apr 2013 05:13:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Apr 2013 05:13:41 +0000 (UTC) Cc: guile-devel@gnu.org To: Daniel Hartwig Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 01 07:14:05 2013 Return-path: Envelope-to: guile-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 1UMX4B-0001vI-1U for guile-devel@m.gmane.org; Mon, 01 Apr 2013 07:13:59 +0200 Original-Received: from localhost ([::1]:46004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMX3m-00050M-Gf for guile-devel@m.gmane.org; Mon, 01 Apr 2013 01:13:34 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMX3j-00050H-0q for guile-devel@gnu.org; Mon, 01 Apr 2013 01:13:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMX3d-0001D7-AP for guile-devel@gnu.org; Mon, 01 Apr 2013 01:13:30 -0400 Original-Received: from mail-pd0-f176.google.com ([209.85.192.176]:53259) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMX3d-0001Cx-48 for guile-devel@gnu.org; Mon, 01 Apr 2013 01:13:25 -0400 Original-Received: by mail-pd0-f176.google.com with SMTP id r11so1038299pdi.35 for ; Sun, 31 Mar 2013 22:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:subject:from:to:cc:date:in-reply-to :references:organization:content-type:x-mailer:mime-version :content-transfer-encoding; bh=jtCanHYh+qo4c5um/bghcBD6f6s3U+iAKTuAOGZv8YY=; b=NP8kri4RsoZkx3xscU+2rNAHaXHBszTVCS24jGfgnDvzxtOYE34uXhXU+D+pDFixgS muJHGuCnufnxokr2ccLvm3wwURyzpbj8TeMFYY/n5NIX6SEgG3wtElz+rDLLdtQGuc3b 2mQZF3tJLatQmDiXZJap1hJ/jQQk/xlh2Ek7rI3WrcBVrqTjBg6LfKvk2TJSs9yAMNCR nBaQW/ZFvgLgITvSD7dA+iaSk8jdydzHN9GVeqDgHIA1qpGT8UZNPlcOwZCfWnZkTWhB j/MynENEYwtPPX1mUXui54Q0DjRY+o++UsIT/xz5ebZ6wGaYVQQH2AEETL20P/X4U3NP nQOA== X-Received: by 10.68.107.4 with SMTP id gy4mr16519722pbb.153.1364793204253; Sun, 31 Mar 2013 22:13:24 -0700 (PDT) Original-Received: from [147.2.147.112] ([61.14.130.226]) by mx.google.com with ESMTPS id i10sm12388140pbd.1.2013.03.31.22.13.22 (version=SSLv3 cipher=RC4-SHA bits=128/128); Sun, 31 Mar 2013 22:13:23 -0700 (PDT) In-Reply-To: X-Mailer: Evolution 3.4.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.192.176 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16082 Archived-At: On Mon, 2013-04-01 at 12:39 +0800, Daniel Hartwig wrote: > 2013/4/1 Nala Ginrut : > > I've tried to implement a function to mimic string multiply like Python: > > "asdf" * 10 > > > > --------------code---------------- > > (define (str* str n) > > (format #f "~{~a~}" (make-list n str))) > > > > or > > > > (define (str* str n) > > (string-join (make-list n str) "")) > > --------------end----------------- > > > > > > Those are both very general mechanisms, it does not suprise me that > they are less than efficient for very large N. Although I can not > comment whether this is a worthwhile issue to address, I offer this > snippet as a hint of something perhaps better for your specific case: > > (define (str* str n) > (call-with-output-string > (lambda (p) > (let lp ((n n)) > (unless (zero? n) > (display str p) > (lp (1- n))))))) > Thanks! Good performance for such a function. ;-) > Out of curiousity, how does the performance figures you showed compare > to the Python operator for similarly large values of N? Python does this very quickly, but I think your hint is enough for that. My ideas are too elegant-pursuing. Anyway, string-join is so slowly beyond my expectation. Regards.