From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Hartwig Newsgroups: gmane.lisp.guile.devel Subject: Re: Extremly slow for format & string-join Date: Mon, 1 Apr 2013 12:39:02 +0800 Message-ID: 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 X-Trace: ger.gmane.org 1364791151 30579 80.91.229.3 (1 Apr 2013 04:39:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Apr 2013 04:39:11 +0000 (UTC) Cc: guile-devel@gnu.org To: Nala Ginrut Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 01 06:39:38 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 1UMWWu-0005qu-Ra for guile-devel@m.gmane.org; Mon, 01 Apr 2013 06:39:36 +0200 Original-Received: from localhost ([::1]:40418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMWWW-0005cH-Cw for guile-devel@m.gmane.org; Mon, 01 Apr 2013 00:39:12 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMWWR-0005Y0-IR for guile-devel@gnu.org; Mon, 01 Apr 2013 00:39:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMWWO-0000pP-09 for guile-devel@gnu.org; Mon, 01 Apr 2013 00:39:07 -0400 Original-Received: from mail-ie0-x229.google.com ([2607:f8b0:4001:c03::229]:49069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMWWN-0000pJ-SE for guile-devel@gnu.org; Mon, 01 Apr 2013 00:39:03 -0400 Original-Received: by mail-ie0-f169.google.com with SMTP id qd14so2036849ieb.28 for ; Sun, 31 Mar 2013 21:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=6Yo54SEr5Nev8kf7n/nFX0fc48weSUYymoDvl7695WQ=; b=HBUeERMrqhDW5snL8MsngqdfkEBm0IIZq/ULeYWM1W9wJW/umVuwJDtkL/JO1zEaug ihM0BNquycaakMv2fG2lDKB1vD1lHkGdosrCnh+Tevm3o3zg3E0pDgZJLv67pRsEz9gD Nk9hDlPvwnyxDpgDCDt7koHdDxQJk0VQ3zDjjNi3EoGqjIvP0O2WtkFuTnGU4qLD7EBz CD9zH3d2GkXnKLnYxuXEqVNPIMg6Osb+vOEFXcYejRCsVCMdPJ7SLuIuRzRCQ5HkgRLL jnJ/gWfk98YEUAYRfGdV+aD5CrW+om5gsC/zkV4TpLG/+FnZrIVGM5U91Qr7ZkCOJtbl qotw== X-Received: by 10.50.134.4 with SMTP id pg4mr2951883igb.96.1364791142954; Sun, 31 Mar 2013 21:39:02 -0700 (PDT) Original-Received: by 10.64.26.168 with HTTP; Sun, 31 Mar 2013 21:39:02 -0700 (PDT) In-Reply-To: <1364788801.4639.6.camel@Renee-desktop.suse> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c03::229 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:16081 Archived-At: 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))))))) Out of curiousity, how does the performance figures you showed compare to the Python operator for similarly large values of N?