From f5413408741893ea24d775827e99d42973b87b63 Mon Sep 17 00:00:00 2001 From: Timofey Potapov Date: Fri, 20 Sep 2024 05:42:19 +0200 Subject: [PATCH] 1.28 - 2024-09-20 Added commands: max, min (from List::Util). Added limit to number of processes with runf (currently set to 20). Updated pod. --- Changes | 8 ++++++ README.md | 48 +++++++++++++++++++++++++++++--- lib/e.pm | 76 +++++++++++++++++++++++++++++++++++++++++++++++---- t/01-simple.t | 14 ++++++++++ 4 files changed, 136 insertions(+), 10 deletions(-) diff --git a/Changes b/Changes index 2b6a373..3ed8ee6 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,13 @@ Revision history for e +================= +1.28 - 2024-09-20 +================= + +Added commands: max, min (from List::Util). +Added limit to number of processes with runf (currently set to 20). +Updated pod. + ================= 1.27 - 2024-08-08 ================= diff --git a/README.md b/README.md index 563526c..4a55d47 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ ⠹⡽⣾⣿⠹⣿⣆⣾⢯⣿⣿ ⡞ ⠻⣿⣿⣿⠁ ⢠⣿⢏ ⡀ ⡟ ⢀⣴⣿⠃⢁⡼⠁ ⠈ ⠈⠛ ⢻⣿⣧⢸⢟⠶⢾⡇ ⣸⡿⠁ ⢠⣾⡟⢼ ⣷ ⡇ ⣰⠋⠙⠁ ⠈⣿⣻⣾⣦⣇⢸⣇⣀⣶⡿⠁⣀⣀⣾⢿⡇⢸ ⣟⡦⣧⣶⠏ unleashed - ⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.27 + ⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.28 ⢻⡄ ⠐⠚⠋⣠⡾⣧⣿⠁⠙⢳⣽⡟ ⠈⠳⢦⣤⣤⣀⣤⡶⠛ ⠈⢿⡆ ⢿⡇ ⠈ ⠈⠓ ⠈ @@ -153,7 +153,18 @@ Simple debugger on the command line: Show a stack trace. - trace( $depth=1 ) + trace( OPTIONS ) + +OPTIONS: + + -levels => NUM, # How many scope levels to show. + NUM, # Same. + + -raw => 1, # Include internal calls. + -NUM, # Same. + + -message => STR, # Message to display. + STR, # Same. ### watch @@ -203,6 +214,13 @@ Benchmark and compare different pieces of code. fast => sub{ ... }, }, 10000; + $ perl -Me -e '$v = 333; n { concat => sub { 111 . $v }, interp => sub { "111$v" }, list => sub { 111,$v } }, 100000000' + + Rate interp concat list + interp 55248619/s -- -6% -62% + concat 58479532/s 6% -- -60% + list 144927536/s 162% 148% -- + ## Format Conversions ### j @@ -399,6 +417,22 @@ Turn string into a [Mojo::File](https://metacpan.org/pod/Mojo%3A%3AFile) object. $ perl -Me -e 'say r j f("hello.json")->slurp' +## Math Help + +### max + +Get the biggest number in a list. + + $ perl -Me -e 'say max 2,4,1,3' + 4 + +### min + +Get the smallest number in a list. + + $ perl -Me -e 'say max 2,4,1,3' + 1 + ## Output ### say @@ -517,9 +551,13 @@ Turn a string into a [Mojo::URL](https://metacpan.org/pod/Mojo%3A%3AURL) object. This sector includes commands to run asynchronous (or pseudo-async) operations. -It is not exturely clear with method to always use. +It is not entirely clear which method to always use. -Typically using threads (with `runt`) is the fastest. +`runf` limits to number of action or 20 (whichever is smaller). + +`runt` and `runio` have no such limits. + +Typically using threads (with `runt`) seems to be fastest. Some statistics using different run commands: @@ -569,6 +607,8 @@ Returns the results. Takes much overhead to start up! +Will use up to 20 processes. + ### runio Run tasks in parallel using [Mojo::IOLoop](https://metacpan.org/pod/Mojo%3A%3AIOLoop). diff --git a/lib/e.pm b/lib/e.pm index c745f79..111a65a 100644 --- a/lib/e.pm +++ b/lib/e.pm @@ -30,7 +30,7 @@ package e; ⠹⡽⣾⣿⠹⣿⣆⣾⢯⣿⣿ ⡞ ⠻⣿⣿⣿⠁ ⢠⣿⢏ ⡀ ⡟ ⢀⣴⣿⠃⢁⡼⠁ ⠈ ⠈⠛ ⢻⣿⣧⢸⢟⠶⢾⡇ ⣸⡿⠁ ⢠⣾⡟⢼ ⣷ ⡇ ⣰⠋⠙⠁ ⠈⣿⣻⣾⣦⣇⢸⣇⣀⣶⡿⠁⣀⣀⣾⢿⡇⢸ ⣟⡦⣧⣶⠏ unleashed - ⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.27 + ⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.28 ⢻⡄ ⠐⠚⠋⣠⡾⣧⣿⠁⠙⢳⣽⡟ ⠈⠳⢦⣤⣤⣀⣤⡶⠛ ⠈⢿⡆ ⢿⡇ ⠈ ⠈⠓ ⠈ @@ -45,7 +45,7 @@ use 5.006; use strict; use warnings; -our $VERSION = '1.27'; +our $VERSION = '1.28'; =head1 SYNOPSIS @@ -171,7 +171,18 @@ Simple debugger on the command line: Show a stack trace. - trace( $depth=1 ) + trace( OPTIONS ) + +OPTIONS: + + -levels => NUM, # How many scope levels to show. + NUM, # Same. + + -raw => 1, # Include internal calls. + -NUM, # Same. + + -message => STR, # Message to display. + STR, # Same. =head3 watch @@ -221,6 +232,13 @@ Benchmark and compare different pieces of code. fast => sub{ ... }, }, 10000; + $ perl -Me -e '$v = 333; n { concat => sub { 111 . $v }, interp => sub { "111$v" }, list => sub { 111,$v } }, 100000000' + + Rate interp concat list + interp 55248619/s -- -6% -62% + concat 58479532/s 6% -- -60% + list 144927536/s 162% 148% -- + =cut =head2 Format Conversions @@ -427,6 +445,24 @@ Turn string into a L object. =cut +=head2 Math Help + +=head3 max + +Get the biggest number in a list. + + $ perl -Me -e 'say max 2,4,1,3' + 4 + +=head3 min + +Get the smallest number in a list. + + $ perl -Me -e 'say max 2,4,1,3' + 1 + +=cut + =head2 Output =head3 say @@ -549,9 +585,13 @@ Turn a string into a L object. This sector includes commands to run asynchronous (or pseudo-async) operations. -It is not exturely clear with method to always use. +It is not entirely clear which method to always use. -Typically using threads (with C) is the fastest. +C limits to number of action or 20 (whichever is smaller). + +C and C have no such limits. + +Typically using threads (with C) seems to be fastest. Some statistics using different run commands: @@ -601,6 +641,8 @@ Returns the results. Takes much overhead to start up! +Will use up to 20 processes. + =head3 runio Run tasks in parallel using L. @@ -913,6 +955,26 @@ sub import { Mojo::File::path( @_ ); }, + ###################################### + # Math Help + ###################################### + + max => sub { + if ( !$imported{$caller}{"List::Util"}++ ) { + require List::Util; + } + + List::Util::max( @_ ); + }, + + min => sub { + if ( !$imported{$caller}{"List::Util"}++ ) { + require List::Util; + } + + List::Util::min( @_ ); + }, + ###################################### # Output ###################################### @@ -1072,7 +1134,9 @@ sub import { require Parallel::ForkManager; } - my $pm = Parallel::ForkManager->new( ~~ @_ ); + my $MAX_PROCESSES = 20; + my $processes = ( @_ > $MAX_PROCESSES ) ? $MAX_PROCESSES : @_; + my $pm = Parallel::ForkManager->new( $processes ); my @res; $pm->run_on_finish( diff --git a/t/01-simple.t b/t/01-simple.t index b411cc1..1983a27 100644 --- a/t/01-simple.t +++ b/t/01-simple.t @@ -253,6 +253,20 @@ is "cpuinfo", "f - basename"; +###################################### +# Math Help +###################################### + +is + max(10,20,9,15), + 20, + "max - sanity check"; + +is + min(10,20,9,15), + 9, + "min - sanity check"; + ###################################### # Output ######################################