From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Execution speed Date: Sun, 19 Mar 2017 11:12:59 -0400 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1489936427 23741 195.159.176.226 (19 Mar 2017 15:13:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Mar 2017 15:13:47 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 19 16:13:41 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpcWZ-0005an-Vz for ged-emacs-devel@m.gmane.org; Sun, 19 Mar 2017 16:13:40 +0100 Original-Received: from localhost ([::1]:57151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpcWg-0006WN-0O for ged-emacs-devel@m.gmane.org; Sun, 19 Mar 2017 11:13:46 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpcW5-0006Ux-Gl for emacs-devel@gnu.org; Sun, 19 Mar 2017 11:13:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpcW0-0003ZJ-J1 for emacs-devel@gnu.org; Sun, 19 Mar 2017 11:13:09 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:14798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpcW0-0003Yu-Cy for emacs-devel@gnu.org; Sun, 19 Mar 2017 11:13:04 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AnDQAjn85Y/yTkr2xdHQEFAQsBg1EiHyCBC4hqhQZzkQ8BlRmCDhoQhXIEgwRAGAECAQEBAQEBAWsohXJyJhgNijcOomCSLIphD5BdhRkFnE2BU4ImgwCOGYd4hmSSFIFEHziBBCMWCCyESAyCYCSKPwEBAQ X-IPAS-Result: A0AnDQAjn85Y/yTkr2xdHQEFAQsBg1EiHyCBC4hqhQZzkQ8BlRmCDhoQhXIEgwRAGAECAQEBAQEBAWsohXJyJhgNijcOomCSLIphD5BdhRkFnE2BU4ImgwCOGYd4hmSSFIFEHziBBCMWCCyESAyCYCSKPwEBAQ X-IronPort-AV: E=Sophos;i="5.36,189,1486443600"; d="el'?scan'208";a="295778345" Original-Received: from 108-175-228-36.dsl.teksavvy.com (HELO ceviche.home) ([108.175.228.36]) by smtp.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Mar 2017 11:13:02 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id DD9A1661A5; Sun, 19 Mar 2017 11:12:59 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:213154 Archived-At: --=-=-= Content-Type: text/plain Someone on SO reported a surprising behavior where a recursive implementation of `gcd` turned out faster than the iterative version: http://stackoverflow.com/questions/42792988/ The more surprising thing is that when I try it I get the opposite result, even though it's basically on the same kind of system (GNU/Linx x86). I'm curious where the difference might come from. Could you guys try out the test? Just do `emacs -Q --batch -l .../ir-test.el`. Here's what I got: % emacs24 -Q --batch -l ~/tmp/ir-test.el Interpreted: Iterative=1.770s; Recursive=1.937s Bytecompiled: Iterative=1.187s; Recursive=1.496s % .../src/emacs -Q --batch -l ~/tmp/ir-test.el Interpreted: Iterative=4.496s; Recursive=4.595s Bytecompiled: Iterative=2.471s; Recursive=2.983s where `emacs24` is Debian's whereas the other one is my locally built&hacked version with debugging assertions and stuff. Stefan --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=ir-test.el Content-Transfer-Encoding: quoted-printable ;; This buffer is for notes you don't want to save, and for Lisp evaluation. ;; If you want to create a file, visit that file with C-x C-f, ;; then enter the text in that file's own buffer. (defun sm-gcdi (a b) (let ((x a) (y b) r) (while (not (zerop y)) (setq r (mod x y) x y y r)) x)) (defun sm-gcdr (a b) (if (zerop b) a (sm-gcdr b (mod a b)))) (defun sm-test-iterative () (let ((start (float-time))) (dotimes (_ 100000) (sm-gcdi 14472334024676221 8944394323791464)) (- (float-time) start))) (defun sm-test-recursive () (let ((start (float-time))) (dotimes (_ 100000) (sm-gcdr 14472334024676221 8944394323791464)) (- (float-time) start))) (message "Interpreted: Iterative=3D%.3fs; Recursive=3D%.3fs" (sm-test-iterative) (sm-test-recursive)) (byte-compile 'sm-gcdi) (byte-compile 'sm-gcdr) (message "Bytecompiled: Iterative=3D%.3fs; Recursive=3D%.3fs" (sm-test-iterative) (sm-test-recursive)) --=-=-=--