Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Those who don't understand Linux are doomed to reinvent it, poorly. -- unidentified source


devel / comp.lang.perl.misc / Re: non-continuous hash

SubjectAuthor
* non-continuous hashDr Eberhard W Lisse
+* Re: non-continuous hashJLM
|`* Re: non-continuous hashJLM
| `* Re: non-continuous hashJLM
|  `* Re: non-continuous hashDr Eberhard Lisse
|   `* Re: non-continuous hashBo Lindbergh
|    +- Re: non-continuous hashDr Eberhard Lisse
|    `- Re: non-continuous hashDr Eberhard Lisse
+* Re: non-continuous hashBob Nichols
|`* Re: non-continuous hashRainer Weikusat
| `* Re: non-continuous hashDr Eberhard Lisse
|  `* Re: non-continuous hashRainer Weikusat
|   `- Re: non-continuous hashDr Eberhard W Lisse
`- Re: non-continuous hashRainer Weikusat

1
non-continuous hash

<jidq2uFkb2tU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=298&group=comp.lang.perl.misc#298

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news-2.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: nospam@lisse.NA (Dr Eberhard W Lisse)
Newsgroups: comp.lang.perl.misc
Subject: non-continuous hash
Date: Sun, 3 Jul 2022 17:14:35 +0200
Lines: 44
Message-ID: <jidq2uFkb2tU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net v+VhJt4uIc9vIlKtNP/PlQd1yBRWY1uJ83/RrJQTbpod56ZnZD
Cancel-Lock: sha1:Ro1DMACAxWrFjHd9TWGwsXs9nbI=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.10.0
Content-Language: en-US
 by: Dr Eberhard W Lisse - Sun, 3 Jul 2022 15:14 UTC

Having something like:

[...]
my $statement = qq/
SELECT exchangerate, transdate
FROM exchangerate
ORDER BY transdate
/;
$statement = $TABLE->prepare ($statement);
$statement->execute () or die $TABLE->errstr;
my %exchangrate;
while (@row = $statement->fetchrow_array) {
$exchangrate{$row[1]} = $row[0];
}
foreach $key ( sort (keys(%exchangrate))) {
print "$key: $exchangrate{$key}\n"
}
[...]

results in something like

[...]
2022-06-19: 0.855
2022-06-21: 0.8601
2022-06-22: 0.8589
2022-06-23: 0.8582
2022-06-29: 0.8646
[...]

which is non-continuous mainly because of weekends and so on.

How do I fill up the empty key-value pairs by way of the last existing
pair?

Ie in this example, the value for 2022-06-20 should also be 0.855, and
the values for 2022-06-24/5/6/7/8 should all be 0.8582.

Even cooler would be to take the "closes value, ie 2022-06-24/5 should
have the (same) value from 2022-06-23 and 2022-06-27/8 should get the
ones from 2022-06-29. But that's not a requirement,

greetings, el

Re: non-continuous hash

<t9sjnj$1pbl$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=299&group=comp.lang.perl.misc#299

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!aioe.org!Wkkd1JLJBBzE7hUfzZOHUw.user.46.165.242.91.POSTED!not-for-mail
From: jesuslozanomosterin@gmail.com (JLM)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Sun, 3 Jul 2022 19:30:26 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t9sjnj$1pbl$1@gioia.aioe.org>
References: <jidq2uFkb2tU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="58741"; posting-host="Wkkd1JLJBBzE7hUfzZOHUw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: es-ES
 by: JLM - Sun, 3 Jul 2022 17:30 UTC

El 3/7/22 a las 17:14, Dr Eberhard W Lisse escribió:
>   foreach $key ( sort (keys(%exchangrate))) {
>         print "$key: $exchangrate{$key}\n"
>     }
>     [...]
>
> results in something like
>
>     [...]
>     2022-06-19: 0.855
>     2022-06-21: 0.8601
>     2022-06-22: 0.8589
>     2022-06-23: 0.8582
>     2022-06-29: 0.8646
>     [...]
>
> which is non-continuous mainly because of weekends and so on.
>
>
> How do I fill up the empty key-value pairs by way of the last existing
> pair?
>
> Ie in this example, the value for 2022-06-20 should also be 0.855, and
> the values for 2022-06-24/5/6/7/8 should all be 0.8582.
>

for $key ( sort keys %exchangerate ) {
if ($key =~ /(\d+)\-(\d+)\-(\d+)/) {
my $date = $3;
if ($date <= 30){
my $c = 1
until (exists $exchagerate{"$1-$2-".$date+$c}){
$exchangerate{"$1-$2-".$date+$c} =$exchangerate{$key};
$c++;
}
}
}
}

Try this. Untested.

--
http://gamo.sdf-eu.org/index.html # ?
World peace, no less!

Re: non-continuous hash

<ta0h8f$3mb$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=301&group=comp.lang.perl.misc#301

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!aioe.org!Wkkd1JLJBBzE7hUfzZOHUw.user.46.165.242.91.POSTED!not-for-mail
From: jesuslozanomosterin@gmail.com (JLM)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 5 Jul 2022 07:12:47 +0200
Organization: Aioe.org NNTP Server
Message-ID: <ta0h8f$3mb$1@gioia.aioe.org>
References: <jidq2uFkb2tU1@mid.individual.net> <t9sjnj$1pbl$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="3787"; posting-host="Wkkd1JLJBBzE7hUfzZOHUw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: es-ES
 by: JLM - Tue, 5 Jul 2022 05:12 UTC

El 3/7/22 a las 19:30, JLM escribió:
> El 3/7/22 a las 17:14, Dr Eberhard W Lisse escribió:
>>    foreach $key ( sort (keys(%exchangrate))) {
>>          print "$key: $exchangrate{$key}\n"
>>      }
>>      [...]
>>
>> results in something like
>>
>>      [...]
>>      2022-06-19: 0.855
>>      2022-06-21: 0.8601
>>      2022-06-22: 0.8589
>>      2022-06-23: 0.8582
>>      2022-06-29: 0.8646
>>      [...]
>>
>> which is non-continuous mainly because of weekends and so on.
>>
>>
>> How do I fill up the empty key-value pairs by way of the last existing
>> pair?
>>
>> Ie in this example, the value for 2022-06-20 should also be 0.855, and
>> the values for 2022-06-24/5/6/7/8 should all be 0.8582.
>>
>
> for $key ( sort keys %exchangerate ) {
>       if ($key =~ /(\d+)\-(\d+)\-(\d+)/) {
>           my $date = $3;
>           if ($date <= 30){
>             my $c = 1

$c = spritf "%02d", $date+$c; # let's try to fix things

            until  (exists $exchagerate{"$1-$2-$c"}){
$exchangerate{"$1-$2-$c"} =$exchangerate{$key};
>                 $c++;

$c = sprintf "%02d", $c; #

>             }
>            }
>       }
> }
>
> Try this. Untested.
>

Still untested. Performance issues I suppose are not a case.

--
http://gamo.sdf-eu.org/index.html # ?
World peace, no less!

Re: non-continuous hash

<ta16t2$rk7$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=302&group=comp.lang.perl.misc#302

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!aioe.org!Wkkd1JLJBBzE7hUfzZOHUw.user.46.165.242.91.POSTED!not-for-mail
From: jesuslozanomosterin@gmail.com (JLM)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 5 Jul 2022 13:22:10 +0200
Organization: Aioe.org NNTP Server
Message-ID: <ta16t2$rk7$1@gioia.aioe.org>
References: <jidq2uFkb2tU1@mid.individual.net> <t9sjnj$1pbl$1@gioia.aioe.org>
<ta0h8f$3mb$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="28295"; posting-host="Wkkd1JLJBBzE7hUfzZOHUw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: es-ES
 by: JLM - Tue, 5 Jul 2022 11:22 UTC

El 5/7/22 a las 7:12, JLM escribió:
>> for $key ( sort keys %exchangerate ) {
>>        if ($key =~ /(\d+)\-(\d+)\-(\d+)/) {
>>            my $date = $3;
>>            if ($date <= 30){
>>              my $c = 1
>
> $c = spritf "%02d", $date+$c;   # let's try to fix things
>
>               until  (exists $exchagerate{"$1-$2-$c"}){
>          $exchangerate{"$1-$2-$c"} =$exchangerate{$key};
>>                  $c++;

last if ($c > 31);

>
> $c = sprintf "%02d", $c;       #
>
>>              }
>>             }
>>        }
>> }
>>
>> Try this. Untested.
>>

A question arises here. For how many days have sense to have
no data? Is it possible to happen in the edge of one month
to another? Then, similar arrangements should be done to the
number of month, and so on.

Best.

--
http://gamo.sdf-eu.org/index.html # ?
World peace, no less!

Re: non-continuous hash

<20220705130042.zbqhv6dhnuj2bljm@erinaceus.ulex.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=303&group=comp.lang.perl.misc#303

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Bob.Nichols@ulex.org.invalid (Bob Nichols)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 5 Jul 2022 14:00:42 +0100
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <20220705130042.zbqhv6dhnuj2bljm@erinaceus.ulex.org>
References: <jidq2uFkb2tU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Info: reader01.eternal-september.org; posting-host="47adc2bbd6030965cbc0e27119906d5b";
logging-data="3908422"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tAIIoUTXUwGkr8sT2Fb1goAH9rE1WIkE="
User-Agent: NeoMutt/20201127
Cancel-Lock: sha1:QuD6AMVKgNAtVYfdM7efi5FeAVc=
In-Reply-To: <jidq2uFkb2tU1@mid.individual.net>
Content-Disposition: inline
 by: Bob Nichols - Tue, 5 Jul 2022 13:00 UTC

#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw/mktime strftime/;

# This is just to get some values into %Rate for the demo:
# You should populate %Rate properly with your database
# selection code (as %exchangrate in your post).
my %Rate = (
'2022-06-19' => 0.855,
'2022-06-21' => 0.8601,
'2022-06-22' => 0.8589,
'2022-06-23' => 0.8582,
'2022-06-29' => 0.8646,
);
my @Dates = sort keys %Rate;

sub timestamp {
# Convert an ISO8601 date string into a UNIX timestamp
$_[0] =~ /^(\d\d\d\d)-?(\d\d)-?(\d\d)$/a;
return mktime(0, 0, 12, $3+0, $2-1, $1-1900);
}

sub iso8601 {
# Convert a UNIX timestamp into an ISO8601 date string
return strftime('%F', localtime($_[0]));
}

sub previous_date {
my $date = $_[0];
return $date if exists $Rate{$date};
return (grep $_ lt $date, @Dates)[-1];
}

sub nearest_date {
my $date = $_[0];
return $date if exists $Rate{$date};
my $prev_date = (grep $_ lt $date, @Dates)[-1];
my $next_date = (grep $_ gt $date, @Dates)[0];
my $prev_gap = timestamp($date) - timestamp($prev_date);
my $next_gap = timestamp($next_date) - timestamp($date);
return $prev_gap <= $next_gap ? $prev_date : $next_date;
}

# Now we have all we need to add missing values to %Rate.

printf "Original %%Rate contains %d values:\n",
scalar keys %Rate;
printf "$_\t$Rate{$_}\n" foreach sort keys %Rate;

# Iterate through every date between the first value and
# the last value in @Dates:
for (
my $date = $Dates[0];
$date le $Dates[-1];
$date = iso8601( timestamp($date)+86400 )
) {
next if exists $Rate{$date};
# If you want a use the previous date for a missing value:
my $previous = previous_date($date);
$Rate{$date} = $Rate{$previous};
# or, if you prefer the nearest date instead:
my $nearest = nearest_date($date);
$Rate{$date} = $Rate{$nearest};
}

printf "\nFilled %%Rate contains %d values:\n",
scalar keys %Rate;
printf "$_\t$Rate{$_}\n" foreach sort keys %Rate;

Re: non-continuous hash

<jij055Fd3pfU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=304&group=comp.lang.perl.misc#304

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: nospam@lisse.NA (Dr Eberhard Lisse)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 5 Jul 2022 16:28:50 +0200
Lines: 48
Message-ID: <jij055Fd3pfU1@mid.individual.net>
References: <jidq2uFkb2tU1@mid.individual.net> <t9sjnj$1pbl$1@gioia.aioe.org>
<ta0h8f$3mb$1@gioia.aioe.org> <ta16t2$rk7$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net BQrsS6juu0sxDTBDtr/dtQS+JXEMFK7wbBo6FJfeBJzEhzKOgO
Cancel-Lock: sha1:FkseHZVs2ZlGyo+NNkAYKqiLUfQ=
Content-Language: en-US
In-Reply-To: <ta16t2$rk7$1@gioia.aioe.org>
 by: Dr Eberhard Lisse - Tue, 5 Jul 2022 14:28 UTC

Bob

Thanks, that looks very cool :-)-O

On 05/07/2022 15:00, Bob Nichols wrote:
> #!/usr/bin/perl
[...]

JLM,

Thanks.

It's an exchange rate coming from

http://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html

That implies it doesn't work on the weekends and sometimes my system is
off.

Exactness doesn't really matter for the exchange rate differences in the
book keeping system where this goes, as they are written off once the
financial year has closed and have no tex implications.

Currently I look up the exchange rate for each transaction (between 2
and 100, last week, last month up to the whole of a calendar year) with
an SQL statement which gives me the last one before the date if the date
doesn't have one.

This is reasonably fast, but sending a single SQL statement from Perl
and then doing that with a hash would be obviously faster and some fun
figuring out

Bob's solution seems to be putting me onto the right track, anyway.

greetings, el

On 05/07/2022 13:22, JLM wrote:
[..]
> A question arises here. For how many days have sense to have
> no data? Is it possible to happen in the edge of one month
> to another? Then, similar arrangements should be done to the
> number of month, and so on.
[...]
--
To email me replace 'nospam' with 'el'

Re: non-continuous hash

<87sfnfh6a9.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=305&group=comp.lang.perl.misc#305

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 05 Jul 2022 17:29:34 +0100
Lines: 79
Message-ID: <87sfnfh6a9.fsf@doppelsaurus.mobileactivedefense.com>
References: <jidq2uFkb2tU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net 7J4DfMWvzJzSg1PFYQqTHwBGIaYOpl33Kki7zk6SOpsNuZp70=
Cancel-Lock: sha1:I7ZxP9QxQVfN3Wg4CR6C6YWjxto= sha1:jkKIDFeDiOYs25iYrPn/2Ai5Yx8=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Tue, 5 Jul 2022 16:29 UTC

Dr Eberhard W Lisse <nospam@lisse.NA> writes:

[...]

> [...]
> 2022-06-19: 0.855
> 2022-06-21: 0.8601
> 2022-06-22: 0.8589
> 2022-06-23: 0.8582
> 2022-06-29: 0.8646
> [...]
>
> which is non-continuous mainly because of weekends and so on.
>
>
> How do I fill up the empty key-value pairs by way of the last existing
> pair?

Not overly complicated way of doing that:

------
#* date generator
# my @m_lens = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

sub m_len
{ my ($y, $m) = @_;
my $ml;

$ml = $m_lens[$m - 1];
++$ml if $ml < 30 && !($y & 3) && !($y % 100 == 0 && $y % 400);
return $ml;
}

sub date_counter
{ my ($y, $m, $d) = split('-', $_[0]);

return sub {
++$d;

if ($d > m_len($y, $m)) {
$d = 1;

if ($m < 12) {
++$m;
} else {
$m = 1;
++$y;
}
}

return sprintf('%u-%02u-%02u', $y, $m, $d);
}
}

#* sample input data
# my %data = qw(2022-06-19 0.855
2022-06-21 0.8601
2022-06-22 0.8589
2022-06-23 0.8582
2022-06-29 0.8646);

#* main
# my @dates = sort(keys(%data));
my $dc = date_counter($dates[0]);
my ($cur_v, $n_d);

$cur_v = $data{$dates[0]};

for (@dates[1 .. $#dates]) {
$data{$n_d} = $cur_v while ($n_d = $dc->()) ne $_;
$cur_v = $data{$_};
}

print($_, "\t", $data{$_}, "\n") for sort(keys(%data));

Re: non-continuous hash

<87o7y3h3bk.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=306&group=comp.lang.perl.misc#306

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 05 Jul 2022 18:33:35 +0100
Lines: 45
Message-ID: <87o7y3h3bk.fsf@doppelsaurus.mobileactivedefense.com>
References: <jidq2uFkb2tU1@mid.individual.net>
<20220705130042.zbqhv6dhnuj2bljm@erinaceus.ulex.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net ZXuh8IpM057uakteGTE5egs+0tftLLlwTk4lns8f8hGbTof0g=
Cancel-Lock: sha1:Of5EECXkIfd7exQGlHy0gp4SOJ0= sha1:uJkV36OJVsm2MlUeFS/12ZczYYY=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Tue, 5 Jul 2022 17:33 UTC

Bob Nichols <Bob.Nichols@ulex.org.invalid> writes:
> # This is just to get some values into %Rate for the demo:
> # You should populate %Rate properly with your database
> # selection code (as %exchangrate in your post).
> my %Rate = (
> '2022-06-19' => 0.855,
> '2022-06-21' => 0.8601,
> '2022-06-22' => 0.8589,
> '2022-06-23' => 0.8582,
> '2022-06-29' => 0.8646,
> );
> my @Dates = sort keys %Rate;

[...]

> sub previous_date {
> my $date = $_[0];
> return $date if exists $Rate{$date};
> return (grep $_ lt $date, @Dates)[-1];
> }
>

[...]

> # Iterate through every date between the first value and
> # the last value in @Dates:
> for (
> my $date = $Dates[0];
> $date le $Dates[-1];
> $date = iso8601( timestamp($date)+86400 )
> ) {
> next if exists $Rate{$date};
> my $previous = previous_date($date);
> $Rate{$date} = $Rate{$previous};

[...]

> }

With doing a benchmark, the exact effects of this can't be determined
(and they might not matter much, anyway) but this is a bad algorithm: It
iterates over an array of a certain length and scans the complete array
once for each iteration, hence, it's running time is proportional to the
square of the array length (ie, the algorithm is of quadratic
complexity).

Re: non-continuous hash

<jilcrsFoloeU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=307&group=comp.lang.perl.misc#307

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: nospam@lisse.NA (Dr Eberhard Lisse)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Wed, 6 Jul 2022 14:18:01 +0200
Lines: 38
Message-ID: <jilcrsFoloeU1@mid.individual.net>
References: <jidq2uFkb2tU1@mid.individual.net>
<20220705130042.zbqhv6dhnuj2bljm@erinaceus.ulex.org>
<87o7y3h3bk.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net QV8RyArRhY552zFl8eP3qAMFlp2nkKJhv5kwE2/kSH0xOp3juS
Cancel-Lock: sha1:R58boPrjXU9NlB+s/S+31DQc8/E=
Content-Language: en-US
In-Reply-To: <87o7y3h3bk.fsf@doppelsaurus.mobileactivedefense.com>
 by: Dr Eberhard Lisse - Wed, 6 Jul 2022 12:18 UTC

Rainer,

thank you for your code (in a separate message).

I have modified both to produce identical output (4489 "completed' pairs
from 3897 returned by my SQL statement and then a few identical lines
to measure the time the actual code (without the SQL) takes

Your's takes indeed around 6 milliseconds whereas Bob's takes some 136
milliseconds (on my iMac) without the (print(f) statement(s)).

In practical terms (of my use case) this does not matter as you
suspected quite correctly, because the PostgreSQL server sits on another
continent and hence the execution time of the SQL statement to populate
the hash is the limiting factor, but I will of course now use your's as
speed was the aim of the exercise.

Learned something here.

Thanks, el

On 05/07/2022 19:33, Rainer Weikusat wrote:
> Bob Nichols <Bob.Nichols@ulex.org.invalid> writes:
[...]
> With doing a benchmark, the exact effects of this can't be determined
> (and they might not matter much, anyway) but this is a bad algorithm:
> It iterates over an array of a certain length and scans the complete
> array once for each iteration, hence, it's running time is
> proportional to the square of the array length (ie, the algorithm is
> of quadratic complexity).

On 05/07/2022 18:29, Rainer Weikusat wrote:
[...]
> Not overly complicated way of doing that:
[...]

--
To email me replace 'nospam' with 'el'

Re: non-continuous hash

<tajemc$20ka3$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=308&group=comp.lang.perl.misc#308

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: blgl@stacken.kth.se (Bo Lindbergh)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 12 Jul 2022 11:29:02 +0200
Organization: /etc/organization
Lines: 18
Message-ID: <tajemc$20ka3$1@dont-email.me>
References: <jidq2uFkb2tU1@mid.individual.net> <t9sjnj$1pbl$1@gioia.aioe.org> <ta0h8f$3mb$1@gioia.aioe.org> <ta16t2$rk7$1@gioia.aioe.org> <jij055Fd3pfU1@mid.individual.net>
Injection-Date: Tue, 12 Jul 2022 09:25:33 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="a43b6e40d2b1d1ff2754009331e4b73f";
logging-data="2117955"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iOBbFnuSAc4CDbr04++Ci"
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:a1JFs065guiU5m9QyOzHKlmREBE=
 by: Bo Lindbergh - Tue, 12 Jul 2022 09:29 UTC

In article <jij055Fd3pfU1@mid.individual.net>,
Dr Eberhard Lisse <nospam@lisse.NA> wrote:
> Currently I look up the exchange rate for each transaction (between 2
> and 100, last week, last month up to the whole of a calendar year) with
> an SQL statement which gives me the last one before the date if the date
> doesn't have one.
>
> This is reasonably fast, but sending a single SQL statement from Perl
> and then doing that with a hash would be obviously faster and some fun
> figuring out

You could use a temporary SQLite database to cache an appropriate range
of data from the remote server. Looking up individual dates in this cache
would be very fast, possibly faster than any fill-in-the-holes code written
in Perl.

/Bo Lindbergh

Re: non-continuous hash

<87h73myxw1.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=309&group=comp.lang.perl.misc#309

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!aioe.org!news.freedyn.de!speedkom.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Tue, 12 Jul 2022 19:43:58 +0100
Lines: 14
Message-ID: <87h73myxw1.fsf@doppelsaurus.mobileactivedefense.com>
References: <jidq2uFkb2tU1@mid.individual.net>
<20220705130042.zbqhv6dhnuj2bljm@erinaceus.ulex.org>
<87o7y3h3bk.fsf@doppelsaurus.mobileactivedefense.com>
<jilcrsFoloeU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net OtVajFwKFc11I90yC1e+1gDzkQ2h5A9LfG9QSpMDsMOl7kU/U=
Cancel-Lock: sha1:n6vbrrQka2Ml2ksZZDj2JkNCiMU= sha1:5nMLxNYynOr7kXSBWRFB5WKnu/c=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Tue, 12 Jul 2022 18:43 UTC

Dr Eberhard Lisse <nospam@lisse.NA> writes:
> I have modified both to produce identical output (4489 "completed' pairs
> from 3897 returned by my SQL statement and then a few identical lines
> to measure the time the actual code (without the SQL) takes
>
> Your's takes indeed around 6 milliseconds whereas Bob's takes some 136
> milliseconds (on my iMac) without the (print(f) statement(s)).

That's interesting. I actually expected the opposite result. While I was
using a linear algorithm, the implementation (with a date enumeration
closure) wasn't exactly low-overhead and did a lot of stuff in
Perl. This usually means that the theoretical scalability advantage
doesn't turn into a pratical advantage unless the amount of input data
is insanely large.

Re: non-continuous hash

<jjcgvkFm05vU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=310&group=comp.lang.perl.misc#310

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: nospam@lisse.NA (Dr Eberhard W Lisse)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Fri, 15 Jul 2022 08:49:22 +0200
Lines: 24
Message-ID: <jjcgvkFm05vU1@mid.individual.net>
References: <jidq2uFkb2tU1@mid.individual.net>
<20220705130042.zbqhv6dhnuj2bljm@erinaceus.ulex.org>
<87o7y3h3bk.fsf@doppelsaurus.mobileactivedefense.com>
<jilcrsFoloeU1@mid.individual.net>
<87h73myxw1.fsf@doppelsaurus.mobileactivedefense.com>
Reply-To: nospam@lisse.NA
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net nOU9eZ4/iKdZ4AnrKy2olQNoiWjHQg0RxOSZ4ZhHVKTlFqu8uh
Cancel-Lock: sha1:EGdSQXUOJE4uEP2NFHUEaDUhM8M=
Content-Language: en-US
In-Reply-To: <87h73myxw1.fsf@doppelsaurus.mobileactivedefense.com>
 by: Dr Eberhard W Lisse - Fri, 15 Jul 2022 06:49 UTC

Indeed, the limiting factor is the SQL Query (the server is on another
continent). And at the most 365 rates per annum doesn't bother
PostgreSQL nor Perl :-)-O

Hmm maybe I should measure on my M1 :-)-O

el

On 2022-07-12 20:43 , Rainer Weikusat wrote:
> Dr Eberhard Lisse <nospam@lisse.NA> writes:
>> I have modified both to produce identical output (4489 "completed'
>> pairs from 3897 returned by my SQL statement and then a few identical
>> lines to measure the time the actual code (without the SQL) takes
>>
>> Your's takes indeed around 6 milliseconds whereas Bob's takes some
>> 136 milliseconds (on my iMac) without the (print(f) statement(s)).
>
> That's interesting. I actually expected the opposite result. While I
> was using a linear algorithm, the implementation (with a date
> enumeration closure) wasn't exactly low-overhead and did a lot of
> stuff in Perl. This usually means that the theoretical scalability
> advantage doesn't turn into a practical advantage unless the amount of
> input data is insanely large.

Re: non-continuous hash

<3f54af2f-e10c-3ad6-5fb7-adca38c41a8e@lisse.NA>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=311&group=comp.lang.perl.misc#311

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: nospam@lisse.NA (Dr Eberhard Lisse)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Fri, 15 Jul 2022 11:01:13 +0200
Lines: 32
Message-ID: <3f54af2f-e10c-3ad6-5fb7-adca38c41a8e@lisse.NA>
References: <jidq2uFkb2tU1@mid.individual.net> <t9sjnj$1pbl$1@gioia.aioe.org>
<ta0h8f$3mb$1@gioia.aioe.org> <ta16t2$rk7$1@gioia.aioe.org>
<jij055Fd3pfU1@mid.individual.net> <tajemc$20ka3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net ODP8L26Khy3uYWu+QvMzUAsDH9bfNA4EX4FBQ42QFf39bnL3OI
Cancel-Lock: sha1:vzFHAyuX2zKQz/Y/H9WlUfPJ+n4=
Content-Language: en-US
In-Reply-To: <tajemc$20ka3$1@dont-email.me>
 by: Dr Eberhard Lisse - Fri, 15 Jul 2022 09:01 UTC

Thanks, but besides being more complicated I really doubt that creating
a (temp) SQLite3 table, writing to it and then reading from it before
even doing any comparison will be faster that Rainer's fill-in-the-hole.

el

On 12/07/2022 11:29, Bo Lindbergh wrote:
> In article <jij055Fd3pfU1@mid.individual.net>, Dr Eberhard Lisse
> <nospam@lisse.NA> wrote:
>
>> Currently I look up the exchange rate for each transaction (between 2
>> and 100, last week, last month up to the whole of a calendar year)
>> with an SQL statement which gives me the last one before the date if
>> the date doesn't have one.
>>
>> This is reasonably fast, but sending a single SQL statement from Perl
>> and then doing that with a hash would be obviously faster and some
>> fun figuring out
>
> You could use a temporary SQLite database to cache an appropriate
> range of data from the remote server. Looking up individual dates in
> this cache would be very fast, possibly faster than any
> fill-in-the-holes code written in Perl.
>
>
> /Bo Lindbergh

--
To email me replace 'nospam' with 'el'

Re: non-continuous hash

<jjcon4Fn6hkU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=312&group=comp.lang.perl.misc#312

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: nospam@lisse.NA (Dr Eberhard Lisse)
Newsgroups: comp.lang.perl.misc
Subject: Re: non-continuous hash
Date: Fri, 15 Jul 2022 11:01:22 +0200
Lines: 32
Message-ID: <jjcon4Fn6hkU1@mid.individual.net>
References: <jidq2uFkb2tU1@mid.individual.net> <t9sjnj$1pbl$1@gioia.aioe.org>
<ta0h8f$3mb$1@gioia.aioe.org> <ta16t2$rk7$1@gioia.aioe.org>
<jij055Fd3pfU1@mid.individual.net> <tajemc$20ka3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net CDRUxju+z1ToIoxFO78b3gwjZNRN8z2RC8BxG/el3alir6NtZz
Cancel-Lock: sha1:Qk5Zh/Tq9NJlA6U7SeIUzWZPXwg=
Content-Language: en-US
In-Reply-To: <tajemc$20ka3$1@dont-email.me>
 by: Dr Eberhard Lisse - Fri, 15 Jul 2022 09:01 UTC

Thanks, but besides being more complicated I really doubt that creating
a (temp) SQLite3 table, writing to it and then reading from it before
even doing any comparison will be faster that Rainer's fill-in-the-hole.

el

On 12/07/2022 11:29, Bo Lindbergh wrote:
> In article <jij055Fd3pfU1@mid.individual.net>, Dr Eberhard Lisse
> <nospam@lisse.NA> wrote:
>
>> Currently I look up the exchange rate for each transaction (between 2
>> and 100, last week, last month up to the whole of a calendar year)
>> with an SQL statement which gives me the last one before the date if
>> the date doesn't have one.
>>
>> This is reasonably fast, but sending a single SQL statement from Perl
>> and then doing that with a hash would be obviously faster and some
>> fun figuring out
>
> You could use a temporary SQLite database to cache an appropriate
> range of data from the remote server. Looking up individual dates in
> this cache would be very fast, possibly faster than any
> fill-in-the-holes code written in Perl.
>
>
> /Bo Lindbergh

--
To email me replace 'nospam' with 'el'


devel / comp.lang.perl.misc / Re: non-continuous hash

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor