Sort IP List

classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
if you replace ip2dec with the same functionality as Hermann's (HH) function with

private function ip2dec2 x
   set the itemdel to "."
   return (item 4 of x) + (item 3 of x * 256) + (item 2 of x * 65536) + (item 1 of x * 16777216)
end ip2dec2

then the special sort via function is faster than sorting the 4 items of the IPlist.

Note "private function" saves about 10 percent, overall Hermann's modified script saves about 20 percent compared to Bob's sort by item solution which was fastest up to now.

Tested 100.000 random IP addresses.

Kind regards
Bernd



hh via use-livecode<https://www.mail-archive.com/search?l=use-livecode@...&q=from:%22hh+via+use%5C-livecode%22> Fri, 29 Jun 2018 16:43:38 -0700<https://www.mail-archive.com/search?l=use-livecode@...&q=date:20180629> wrote:

Your IP addresses [0-255].[0-255].[0-255].[0-255]
are the hex IP numbers converted to base 256.
So you may try the following sorting function that
converts the IPs from base 256 to base 10 (decimal).


function ip2dec x
  set itemdel to "."
  repeat with i=0 to 3
    add (item 4-i of x)*256^i to y
  end repeat
  return y
end ip2dec

on mouseUp
  put fld "ips" into s
  sort s numeric by ip2dec(each) # <----
  put s into fld "out"
end mouseUp

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
In reply to this post by Mike Kerner via use-livecode
Remains to remark that the upcoming standard IPv6
with its text representations
(Section 2.2 of https://tools.ietf.org/html/rfc4291)
will require more detailed methods,
both for number base conversion and for item sorts/cosorts
(the items are hex numbers ...)

@Bernd
Depending on the function an inline computation (as Alex denoted)
may be even faster than the private function calls?
Here, with IPv4 addresses, it is faster.



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
Here are some times on my system for comparison (100000 random IPs):

216% - ip2dec: 463 ms
190% - ip2decpvt: 407 ms
171% - ip2dec2: 366 ms
147% - ip2dec2pvt: 314 ms
200% - sortIPList: 427 ms --> original from Bob
100% - sortIPList2: 215 ms --> Alex's inline with constants
152% - sortIPList3: 325 ms --> numtobyte(item 1) &...
107% - sortIPList4: 230 ms --> bitOr instead of +
100% - sortIPList5: 214 ms --> item 4 of each + 256 * (...

sortIPList2 comes out fastest most of the time.  sortIPList5 does come out
ahead on some runs (Alex's alternate code).  I did all of this because I
was curious how the speed of using numtobyte would impact things.  It is
comparable to using a private function (ip2dec2pvt), but still slower than
inline.  While there I decided to also test the bitOr.


On Sat, Jun 30, 2018 at 5:10 AM, hh via use-livecode <
[hidden email]> wrote:

> Remains to remark that the upcoming standard IPv6
> with its text representations
> (Section 2.2 of https://tools.ietf.org/html/rfc4291)
> will require more detailed methods,
> both for number base conversion and for item sorts/cosorts
> (the items are hex numbers ...)
>
> @Bernd
> Depending on the function an inline computation (as Alex denoted)
> may be even faster than the private function calls?
> Here, with IPv4 addresses, it is faster.
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
In reply to this post by Mike Kerner via use-livecode
Hermann,

I did not see Alex's solution until after I posted. I agree that inline is probably always faster.

And after I saw Alex's post I would not have thought that one could do it that way, thanks Alex. On top it is by far the fastest.

On the other hand sort by myFunction(each) is so powerful that you can do things that are probably not possible inline.

Kind regards
Bernd




hh via use-livecode<https://www.mail-archive.com/search?l=use-livecode@...&q=from:%22hh+via+use%5C-livecode%22> Sat, 30 Jun 2018 03:12:55 -0700<https://www.mail-archive.com/search?l=use-livecode@...&q=date:20180630> wrote:


@Bernd
Depending on the function an inline computation (as Alex denoted)
may be even faster than the private function calls?
Here, with IPv4 addresses, it is faster.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
good thread you guys...code optimization quests....what fun.

On Sat, Jun 30, 2018 at 2:01 PM, Niggemann, Bernd via use-livecode <
[hidden email]> wrote:

> Hermann,
>
> I did not see Alex's solution until after I posted. I agree that inline is
> probably always faster.
>
> And after I saw Alex's post I would not have thought that one could do it
> that way, thanks Alex. On top it is by far the fastest.
>
> On the other hand sort by myFunction(each) is so powerful that you can do
> things that are probably not possible inline.
>
> Kind regards
> Bernd
>
>
>
>
> hh via use-livecode<https://www.mail-archive.com/search?l=use-
> [hidden email]&q=from:%22hh+via+use%5C-livecode%22> Sat, 30
> Jun 2018 03:12:55 -0700<https://www.mail-archive.com/search?l=use-
> [hidden email]&q=date:20180630> wrote:
>
>
> @Bernd
> Depending on the function an inline computation (as Alex denoted)
> may be even faster than the private function calls?
> Here, with IPv4 addresses, it is faster.
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

RE: Sort IP List

Mike Kerner via use-livecode
How fortuitous... I am finding the bottlenecks in some code under a deadline
the last few days and found some interesting observations.

1) Assembling, putting data into a field and doing text editing (replace x
with y in fld F1) in an non-visible field object is faster than assembling a
line in a local var and then putting it into the field once. I understand
that I'm moving the data twice but I thought there was some overhead of
field formatting every time I changed the data. apparently not...

I had a function call in a loop with two params and it returned a text
string of a few hundred to a few thousand cars. I changed it to a handler
with three params all by ref(the third being the var that the function
version set. Now I would have though the with everything by ref it would be
faster but in fact it was slower by 50%.

LC makes it so easy to do timings. I actually had fun tracking down and
attacking each bottleneck. Some stuff like putting simple calculations
in-line repeat constructs speeded things up as expected, others befuddled
me.

Ralph DiMola
IT Director
Evergreen Information Services
[hidden email]

-----Original Message-----
From: use-livecode [mailto:[hidden email]] On Behalf
Of Tom Glod via use-livecode
Sent: Saturday, June 30, 2018 3:51 PM
To: How to use LiveCode
Cc: Tom Glod
Subject: Re: Sort IP List

good thread you guys...code optimization quests....what fun.

On Sat, Jun 30, 2018 at 2:01 PM, Niggemann, Bernd via use-livecode <
[hidden email]> wrote:

> Hermann,
>
> I did not see Alex's solution until after I posted. I agree that
> inline is probably always faster.
>
> And after I saw Alex's post I would not have thought that one could do
> it that way, thanks Alex. On top it is by far the fastest.
>
> On the other hand sort by myFunction(each) is so powerful that you can
> do things that are probably not possible inline.
>
> Kind regards
> Bernd
>
>
>
>
> hh via use-livecode<https://www.mail-archive.com/search?l=use-
> [hidden email]&q=from:%22hh+via+use%5C-livecode%22> Sat, 30
> Jun 2018 03:12:55 -0700<https://www.mail-archive.com/search?l=use-
> [hidden email]&q=date:20180630> wrote:
>
>
> @Bernd
> Depending on the function an inline computation (as Alex denoted) may
> be even faster than the private function calls?
> Here, with IPv4 addresses, it is faster.
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
Ralph-

Not that I'm doubting your findings, but those both seem mind-bogglingly
nonsensical to me. Can you post your test code?

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

RE: Sort IP List

Mike Kerner via use-livecode
I agree "mind-bogglingly nonsensical"

Something is very odd. If I open the stack with fresh start of the IDE I
start getting results closer to what I would expect. The by ref is about 5
to 10% faster. NOW.... Every so often when I open the message box things
start getting weird and I get those crazy results. If I close msg then it is
different weird. When I say different I mean that another step in the
process starts taking longer. Close LC and restart and things are back to
normal until I open the message box a few times. No pattern as of yet. But I
do know if you don't open the message box it never goes crazy. I'm going to
dig in and see what's happening here. If I can get a recipe I'm going to
send it off to Panos.

Win 10 VM
LC 9

Ralph DiMola
IT Director
Evergreen Information Services
[hidden email]

-----Original Message-----
From: use-livecode [mailto:[hidden email]] On Behalf
Of Mark Wieder via use-livecode
Sent: Saturday, June 30, 2018 11:05 PM
To: Ralph DiMola via use-livecode
Cc: Mark Wieder
Subject: Re: Sort IP List

Ralph-

Not that I'm doubting your findings, but those both seem mind-bogglingly
nonsensical to me. Can you post your test code?

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
oh yes..... message box makes LC slow to a crawl..I've noticed that. i can
confirm that. Win 10 LC 9 too.

On Mon, Jul 2, 2018 at 12:45 AM, Ralph DiMola via use-livecode <
[hidden email]> wrote:

> I agree "mind-bogglingly nonsensical"
>
> Something is very odd. If I open the stack with fresh start of the IDE I
> start getting results closer to what I would expect. The by ref is about 5
> to 10% faster. NOW.... Every so often when I open the message box things
> start getting weird and I get those crazy results. If I close msg then it
> is
> different weird. When I say different I mean that another step in the
> process starts taking longer. Close LC and restart and things are back to
> normal until I open the message box a few times. No pattern as of yet. But
> I
> do know if you don't open the message box it never goes crazy. I'm going to
> dig in and see what's happening here. If I can get a recipe I'm going to
> send it off to Panos.
>
> Win 10 VM
> LC 9
>
> Ralph DiMola
> IT Director
> Evergreen Information Services
> [hidden email]
>
> -----Original Message-----
> From: use-livecode [mailto:[hidden email]] On
> Behalf
> Of Mark Wieder via use-livecode
> Sent: Saturday, June 30, 2018 11:05 PM
> To: Ralph DiMola via use-livecode
> Cc: Mark Wieder
> Subject: Re: Sort IP List
>
> Ralph-
>
> Not that I'm doubting your findings, but those both seem mind-bogglingly
> nonsensical to me. Can you post your test code?
>
> --
>   Mark Wieder
>   [hidden email]
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
On 07/02/2018 06:59 AM, Tom Glod via use-livecode wrote:
> oh yes..... message box makes LC slow to a crawl..I've noticed that. i can
> confirm that. Win 10 LC 9 too.

I've seen that too, especially when spewing debugging statements to the
messagebox. But not all the time, and nothing I can get a recipe for.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
There used to be a barrage of pending messages generated by the IDE that
were updating in the message box. Look at the messages pane and set it to
auto-update, see if they're still there

--
Jacqueline Landman Gay | [hidden email]
HyperActive Software | http://www.hyperactivesw.com
On July 2, 2018 9:58:40 AM Mark Wieder via use-livecode
<[hidden email]> wrote:

> On 07/02/2018 06:59 AM, Tom Glod via use-livecode wrote:
>> oh yes..... message box makes LC slow to a crawl..I've noticed that. i can
>> confirm that. Win 10 LC 9 too.
>
> I've seen that too, especially when spewing debugging statements to the
> messagebox. But not all the time, and nothing I can get a recipe for.
>
> --
>  Mark Wieder
>  [hidden email]
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Mike Kerner via use-livecode
ok i will try to provide more info on this from my stack when it happens
next.

On Mon, Jul 2, 2018 at 12:17 PM, J. Landman Gay via use-livecode <
[hidden email]> wrote:

> There used to be a barrage of pending messages generated by the IDE that
> were updating in the message box. Look at the messages pane and set it to
> auto-update, see if they're still there
>
> --
> Jacqueline Landman Gay | [hidden email]
> HyperActive Software | http://www.hyperactivesw.com
>
> On July 2, 2018 9:58:40 AM Mark Wieder via use-livecode <
> [hidden email]> wrote:
>
> On 07/02/2018 06:59 AM, Tom Glod via use-livecode wrote:
>>
>>> oh yes..... message box makes LC slow to a crawl..I've noticed that. i
>>> can
>>> confirm that. Win 10 LC 9 too.
>>>
>>
>> I've seen that too, especially when spewing debugging statements to the
>> messagebox. But not all the time, and nothing I can get a recipe for.
>>
>> --
>>  Mark Wieder
>>  [hidden email]
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
12