Re: Optimize script for generating LinuxManBook.pdf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday, 24 November 2023 11:46:30 GMT Alejandro Colomar wrote:
> On Thu, Nov 23, 2023 at 11:12:45PM +0100, Alejandro Colomar wrote:
> > > It looks fine, although you have to run the code in
> > > "prepare_linux_man_book.pl" twice (to avoid using a temporary file).
> > 
> > Yep.  I was wondering if we could change something in the design of
> > prepare_linux_man_book.pl so that it could be run once without needing
> > a temporary file.  Maybe if it could insert something in the pages that
> > the latter troff(1) would process in one take, without having to put all
> > the bookmarks at the start of the file.  That would be an important
> > simplification of the scripts, and probably also an optimization.
> 
> Hi Deri,
> 
> I have another optimization: split the sort.  It reduces around 0.3 s.
> 
> diff --git a/scripts/LinuxManBook/prepare_linux_man_book.pl
> b/scripts/LinuxManBook/prepare_linux_man_book.pl index 0a79df4e5..5a4aad429
> 100755
> --- a/scripts/LinuxManBook/prepare_linux_man_book.pl
> +++ b/scripts/LinuxManBook/prepare_linux_man_book.pl
> @@ -88,7 +88,16 @@ sub BuildBook
>  {
>         print ".pdfpagenumbering D . 1\n";
> 
> -       foreach my $fn (sort sortman glob("$dir/man*/*")) {
> +       foreach my $fn (sort glob("$dir/man*")) {
> +               BuildSec($fn);
> +       }
> +}
> +
> +sub BuildSec
> +{
> +       my $manSdir=shift;
> +
> +       foreach my $fn (sort sortman glob("$manSdir/*")) {
>                 BuildPage($fn);
>         }
>  }
> 
> 
> I didn't think of this as an optimization, but rather to move code from
> BuildPage() into BuildSec().  However, since it doesn't block until all
> of the pages are sorted, it reduces the latency of the script (that's my
> guess).
> 
> I think moving stuff from BuildPage() to BuildSec() would both simplify
> and optimize, so please check it when you can.  (I'm also checking it,
> but while I'm learning Perl with this, I'm still very limited.)
> 
> Cheers,
> Alex

Hi Alex,

I have attached the latest iteration of my work, managed to knock two seconds 
off the current code in your git. It no longer uses temporary files, outputs 
the pdf to stdout, can be run from any directory and runs groff once.

It replaces the complete LinuxManBook directory and the executable is now 
called BuildLinuxMan2.pl.

Cheers 

Deri


Attachment: LinuxManBook.tgz
Description: application/compressed-tar


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux