From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: speeding up Babel Gnuplot Date: Wed, 28 Dec 2016 21:33:00 +0100 Message-ID: <5864217C.7060001@free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMKuF-00072K-UU for emacs-orgmode@gnu.org; Wed, 28 Dec 2016 15:33:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMKuF-00065H-7W for emacs-orgmode@gnu.org; Wed, 28 Dec 2016 15:33:03 -0500 Received: from smtp1-g21.free.fr ([2a01:e0c:1:1599::10]:41775) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cMKuF-00065C-00 for emacs-orgmode@gnu.org; Wed, 28 Dec 2016 15:33:03 -0500 Received: from [IPv6:2a01:e35:2e21:def0:c5ff:52e1:ad66:126e] (unknown [IPv6:2a01:e35:2e21:def0:c5ff:52e1:ad66:126e]) by smtp1-g21.free.fr (Postfix) with ESMTP id B82BCB003E4 for ; Wed, 28 Dec 2016 21:33:00 +0100 (CET) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Babel Gnuplot is quite slow on large tables. Example: 45 seconds for a 1500 rows table. Why? Because orgtbl-to-generic is too slow (or too generic). Its behavior seems to be quadratic O(size^2). Should we bypass it? Should we try to optimize it? Here is a fix to speed up the rendering to a mere fraction of a second. #+BEGIN_SRC elisp (defun org-babel-gnuplot-table-to-data (table data-file params) "Export TABLE to DATA-FILE in a format readable by gnuplot." (let ((org-babel-gnuplot-timestamp-fmt (or (plist-get params :timefmt) "%Y-%m-%d-%H:%M:%S"))) (with-temp-file data-file (mapc (lambda (line) (mapc (lambda (cell) (insert (org-babel-gnuplot-quote-tsv-field cell)) (insert "\t")) line) (insert "\n")) table))) data-file) #+END_SRC And here is a test case. First generate a 1500 rows table: #+BEGIN_SRC elisp :results none (goto-char (point-max)) (insert "#+name: data\n") (let ((i 1500)) (while (> i 0) (goto-char (point-max)) (insert (format "| %4s |\n" i)) (setq i (1- i)))) #+END_SRC Then run Babel Gnuplot: #+BEGIN_SRC gnuplot :var data=data :file x.svg :session none :term svg plot data #+END_SRC