all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* speeding up Babel Gnuplot
@ 2016-12-28 20:33 Thierry Banel
  2016-12-29 20:04 ` Nicolas Goaziou
  2017-01-01 20:17 ` Thierry Banel
  0 siblings, 2 replies; 17+ messages in thread
From: Thierry Banel @ 2016-12-28 20:33 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-01-06 18:24 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-28 20:33 speeding up Babel Gnuplot Thierry Banel
2016-12-29 20:04 ` Nicolas Goaziou
2016-12-29 20:34   ` Thierry Banel
2017-01-01 20:17 ` Thierry Banel
2017-01-01 23:34   ` Nicolas Goaziou
2017-01-02 20:11     ` Thierry Banel
2017-01-03 21:40       ` Thierry Banel
2017-01-03 21:55         ` Nicolas Goaziou
2017-01-03 23:06           ` Thierry Banel
2017-01-04 22:36             ` Nicolas Goaziou
2017-01-05 20:47               ` Thierry Banel
2017-01-06  9:41                 ` Nicolas Goaziou
2017-01-06 18:24                   ` Thierry Banel
2017-01-04 17:32         ` Achim Gratz
2017-01-04 20:29           ` Thierry Banel
2017-01-04 23:15           ` Charles C. Berry
2017-01-05 20:23             ` Thierry Banel

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.