LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Mime-Version:
1.0 (Apple Message framework v1081)
Content-Type:
text/plain; charset=windows-1252
Date:
Tue, 21 Sep 2010 11:52:03 +0930
Reply-To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Subject:
From:
Will Robertson <[log in to unmask]>
Message-ID:
In-Reply-To:
Content-Transfer-Encoding:
8bit
Sender:
Mailing list for the LaTeX3 project <[log in to unmask]>
Parts/Attachments:
text/plain (82 lines)
On 20/09/2010, at 11:27 PM, Frank Mittelbach wrote:

> is there actually any need for the :nnn etc versions?

Not sure, is there?
They seem natural to me; better than nesting multiple :nn commands for more than two Ďandí branches, say.

> I tend to prefer the lisp like versions too ...not because I find them much
> more readable :-) but because I still have a suspicion that the inline coding
> has a performance hit (which is most likely not the case as they are coded by
> Morten, but there you are).

Well, my initial implementation was just going to be

\cs_new:Npn \bool_and_p:nn   #1#2     { \bool_if_p:n { #1 && #2             } }
\cs_new:Npn \bool_and_p:nnn  #1#2#3   { \bool_if_p:n { #1 && #2 && #3       } }
\cs_new:Npn \bool_and_p:nnnn #1#2#3#4 { \bool_if_p:n { #1 && #2 && #3 && #4 } }

to be filled in with more efficient hand-coded versions when time permits. So perhaps not the speed gains you were hoping for, at least straight away :)

In fact, I'm not sure you're going to do that much better unless you want more restricted \bool_and_p:NN versions instead. But how fast do these need to be? In the attached benchmark, I can run

  \bool_if:nTF {
    \intexpr_compare_p:n {1=1} && (
    \intexpr_compare_p:n {2=3} ||
    \intexpr_compare_p:n {4=4} ||
    \intexpr_compare_p:n {1=\error} % is skipped
    ) &&
    !(\intexpr_compare_p:n {2=4})
  }
  {T}{F}

about 13000 times per second on my machine. I don't really have a metric for knowing when how fast is fast enough, though -- perhaps this is too slow. (What's that saying about premature optimisation? :) )

-- Will


\documentclass{minimal}
\usepackage{expl3}

\begin{document}

\ExplSyntaxOn
\batchmode

\def\N{10000}

replicate~ only:~
\pdfresettimer
\prg_replicate:nn {\N} {
  \typeout{x}
}
\newcount\1
\1=\pdfelapsedtime
\number\1
\par

replicate~ with~ boolean~ calculation:~
\pdfresettimer
\prg_replicate:nn {\N} {
  \typeout{
  \bool_if:nTF {
    \intexpr_compare_p:n {1=1} && (
    \intexpr_compare_p:n {2=3} ||
    \intexpr_compare_p:n {4=4} ||
    \intexpr_compare_p:n {1=\error} % is skipped
    ) &&
    !(\intexpr_compare_p:n {2=4})
  }
  {T}{F}
  }
}
\newcount\2
\2=\pdfelapsedtime
\number\2
\par

time~per~loop:~\the\numexpr(1000000*(\2-\1)/\N)/65536\relax\space microseconds

\ExplSyntaxOff
\end{document}

ATOM RSS1 RSS2