in reply to Win32 OLE painfully slow

Win32::OLE is no speed demon, but this code:

use Win32::OLE;

Takes 2 seconds to run on Win2K, AS Perl 5.6.1 Are you sure about where the time is being spent? To use Excel you then have to instantiate an Excel object which also takes a couple of seconds on this box. Nothing takes minutes.

Do you have enough RAM? If you only have 256MB and XP you don't have enough RAM to have many windows open at once before you will start swapping. That might cause that sort of slow down.

As an aside why use Excel for graphing? It has always been rather mediocre. Can I recommend GD::Graph to you. It is fast and has a much nicer interface than (dare I say) anything involving Win32::OLE.

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: Win32 OLE painfully slow
by spurperl (Priest) on Apr 13, 2004 at 11:40 UTC
    use Win32::OLE;

    Takes a second on my PC too (P4 1.7Ghz, 512MB memory). What takes most time is

    use Win32::OLE::Const 'Microsoft Excel';

    I want to use Excel because I want to save these charts so other people will be able to open them and analyze them, using no special purpose tools (only Excel).

      Dunno what your problem is. This code:

      use Win32::OLE; use Win32::OLE::Const; my $xl = Win32::OLE::Const->Load("Microsoft Excel"); foreach my $const (sort keys %$xl) { printf "$const = %s\n", $xl->{$const}; #printf "sub $const { %d }\n", $xl->{$const}; }

      loads and prints all the constants in a couple of seconds. An ugly hack would be to hard code the constants. You could do this simply by using the code above to dump

      sub constname { NNN }

      Cut and paste the output into your code or your own constants module like Win32::OLE::Const::Excel. Leave the generator code there but comment it out. Net effect - you get the constants you need fast. If the constants change just rerun the generator and it will get updated. Not a perfect solution but quite a practical kludge.

      cheers

      tachyon

        It loads and prints all the constants in more than a minute for me (99% of it for loading).

        I'll try to dig into the suggestions other monks gave me (thanks !), but I must say that your kludge really does help, now everything works super fast. This only proves that the problem is in loading the constants.

        Thanks !