in reply to time and mem usage of pgm

In Windows, this does the trick provided whole seconds are good enough:

#! perl -slw use strict; sub mem{ `tasklist /nh /fi "PID eq $$"` =~ m[(\S+ K)$] } END{ print time - $^T, " seconds\nRam:", mem; } sleep $ARGV[0]; __END__ C:\test>junk33 5 5 seconds Ram:4,836 K C:\test>junk33 10 10 seconds Ram:4,832 K

Finding the *nix equivalent of tasklist left as an exercise.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^2: time and mem usage of pgm
by carolw (Sexton) on Mar 10, 2015 at 08:40 UTC

    how is it possible to test in perl if the program is running on win or linux? In this way, the same program can be used on both system and if it is under linux, proc/stat will be used to measure time and mem and if it is win, your code.

      how is it possible to test in perl if the program is running on win or linux?

      Simply:

      if( $^O eq 'MSWin32' ) { ## Do the windows thing } else { ## else do something else }

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

        Does this consider only 32-bits or 64-bit architecture, too?

        I don't know why I got the locale settings problem even if I don't add the proposed code:
        perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = "en_US:en", LC_ALL = (unset), LC_PAPER = "fr_FR.UTF-8", LC_ADDRESS = "fr_FR.UTF-8", LC_MONETARY = "fr_FR.UTF-8", LC_NUMERIC = "fr_FR.UTF-8", LC_TELEPHONE = "fr_FR.UTF-8", LC_IDENTIFICATION = "fr_FR.UTF-8", LC_MEASUREMENT = "fr_FR.UTF-8", LC_TIME = "fr_FR.UTF-8", LC_NAME = "fr_FR.UTF-8", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C").

      You don't need to test, if there is a tasklist.exe pslist.exe of memlist.exe, it doesn't matter what platform it is, their usage is probably the same on win32 and on linux :)

      Devel::CheckOS, Devel::AssertOS

        You don't need to test, if there is a tasklist.exe pslist.exe of memlist.exe, it doesn't matter what platform it is, their usage is probably the same on win32 and on linux :)

        tasklist.exe is an executable that ships as part of windows. Unlikely to be a linux version.

        And as far as I know, no *nix executables are named *.exe


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked