emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Emmanuel Charpentier <emm.charpentier@free.fr>
To: e.fraga@ucl.ac.uk, emacs-orgmode@gnu.org
Subject: when does :cache not cache?
Date: Sun, 24 Oct 2021 13:49:34 +0200	[thread overview]
Message-ID: <f2b7f94fff42ffbf65ce326fdd1a5ba8386c2543.camel@free.fr> (raw)
In-Reply-To: 87mtn1o5mn.fsf@ucl.ac.uk

[-- Attachment #1: Type: text/plain, Size: 1654 bytes --]

Workaround : cache the computations,not the plotting itself (which
should be fast,and must be made on every table, anyway...) :

#+options: toc:nil author:nil

* Main text

Use of a static table:

#+call: timeit()
#+call: testplot[:file test0.pdf](data=table0)
#+call: timeit()

Use of a slow function:

#+call: timeit()
#+call: testplot[:file test1.pdf](data=table1)
#+call: timeit()

Use of a /cached/ slow function:

#+call: timeit()
#+call: testplot[:file test2.pdf](data=table2)
#+call: timeit()

* Annexes :noexport:

This is not exported, but computes results.

#+name: timeit
#+begin_src emacs-lisp
  (format-time-string "%Hh %Mm %Ss")
#+end_src

#+name: table0
| Val | Square |
|-----+--------|
|   0 |      0 |
|   1 |      1 |
|   2 |      4 |
|   3 |      9 |
|   4 |     16 |
#+TBLFM: $2=$1^2

#+name: table1
#+begin_src emacs-lisp
  (sleep-for 5)
  (setq s ( list (list "x" "x^2") 'hline))
  (dotimes (i 5 s) (setq s (append s (list (cons i (list (* i i)))))))
  s
#+end_src

#+RESULTS[46320b31c46cef901580bad78aee7032d97ffe64]: table1
| x | x^2 |
|---+-----|
| 0 |   0 |
| 1 |   1 |
| 2 |   4 |
| 3 |   9 |
| 4 |  16 |


#+name: table2
#+begin_src emacs-lisp :cache yes
  (sleep-for 5)
  (setq s ( list (list "x" "x^2") 'hline))
  (dotimes (i 5 s) (setq s (append s (list (cons i (list (* i i)))))))
  s
#+end_src

#+name: tf
| festfile.pdf ]

#+RESULTS[46320b31c46cef901580bad78aee7032d97ffe64]: table2
| x | x^2 |
|---+-----|
| 0 |   0 |
| 1 |   1 |
| 2 |   4 |
| 3 |   9 |
| 4 |  16 |

#+name: testplot
#+begin_src gnuplot :var data=table0 :exports results
  reset
  plot data with linespoints
#+end_src

HTH,

--
Emmanuel Charpentier


[-- Attachment #2: Type: text/html, Size: 2727 bytes --]

             reply	other threads:[~2021-10-24 11:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-24 11:49 Emmanuel Charpentier [this message]
2021-10-25 10:58 ` Eric S Fraga
  -- strict thread matches above, loose matches on Subject: below --
2021-10-23  9:13 Emmanuel Charpentier
2021-10-23 10:09 ` Eric S Fraga
2021-10-23 15:15   ` Eric S Fraga
2021-10-22  7:55 Eric S Fraga
2021-12-12  7:45 ` Ihor Radchenko
2021-12-13  8:13   ` Eric S Fraga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2b7f94fff42ffbf65ce326fdd1a5ba8386c2543.camel@free.fr \
    --to=emm.charpentier@free.fr \
    --cc=e.fraga@ucl.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: when does :cache not cache?' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).