Meeting Sept 1 2016

Discussion forum for the Southern California LiveCode Developer Group

Moderators: FourthWorld, Klaus, robinmiller

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Meeting Sept 1 2016

Post by bn » Wed Sep 07, 2016 2:57 pm

Hi Clarence,

Richard did an excellent job optimizing the algorithm. I just take the low hanging fruit of adding one line to build the array for the frequency of numbers in the inner loop of Richard's repeat loop. Thus obviating the need to go through the data again for the frequency. Also I locked the screen.

Code: Select all

 -- This is an optimized version
on mouseUp
   answer "This is a Greatly Optimized Version" & cr &\
   "In order to see the optimization between the Load Matrix code you need to analyze at least 1000 Games"
   put empty into field "tNums"
   put empty into field "tRCount"
   put empty into field "totNumsFtr"
   if field "nums" is empty then
      answer "You need to import Past Games in order in order to Anaylze Games"
      exit  mouseUp
   end if
   -- Bypass ask to use fixed value for timing:
   ask "how Many Games do you want to Analyze" 
   # get 5000
   put it into tGames2Analyze
   -- Capture start time:
   put the millisecs into t
   --
   -- Load Matrix
   set itemdel to tab
   set the cursor to watch
   put field "nums" into vNums
   put 1 into tCounter
   
   lock screen -- added BN
   
   -- New method using a template line which is filled in
   -- each time through the loop to avoid item counts:
   --
   -- Load template line:
   put empty into tTemplateLine
   repeat 39
      put space & tab after tTemplateLine
   end repeat
   -- Use a copy for each line, filling in appropriate columns
   -- as it goes:
   repeat for each line tRow in vNums
      put tTemplateLine into tThisLine
      repeat with  tPicks = 6 to 10
         put word tPicks of tRow into tColumn
         
         add 1 to tA[tColumn] -- added BN
         
         put "X" into byte (tColumn *2)-1 of tThisLine         
      end repeat
      put tThisLine & cr after tMatrix
      add 1 to tCounter
      if tCounter >tGames2Analyze then   
         exit repeat
      end if
   end repeat
   
   --
   put tMatrix into field "tNums"
   
   repeat with i = 1 to 39
      put tA[i] &tab after tVals
   end repeat
   put tVals into fld "totNumsFtr"
   --
   -- Display elapsed time:
   unlock screen -- added BN
   answer  " It took"&& the millisecs - t && " milliseconds to complete the analysis"
end mouseUp
I marked my additions with -- BN

I removed old/unused code.

Now if only Dick would chime in...

Kind regards
Bernd

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Meeting Sept 1 2016

Post by FourthWorld » Wed Sep 07, 2016 3:47 pm

Well done, Bernd. Thanks for chiming in.

Too bad you're so far from Pasadena. Many of our meetings lately have involved optimizing code, and I'm sure you'd have as much fun in those meetings as we'd love having you there.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 244
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: Meeting Sept 1 2016

Post by chipsm » Wed Sep 07, 2016 3:54 pm

Thanks Bernd,
It is always good to see other people involved in adding comments and code to samples that people provide.
I haven't added your code yet but did you see any improvement in the timing?
I will modify the code and check.
Thanks, any contributions are always welcome.
Clarence Martin
chipsm@themartinz.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Meeting Sept 1 2016

Post by bn » Wed Sep 07, 2016 4:02 pm

Hi Clarence,
haven't added your code yet but did you see any improvement in the timing?
just put the code into a button "Load Matrix4" and test it, it should work out of the box.

The timing is the surprise part...

Kind regards

Bernd

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 244
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: Meeting Sept 1 2016

Post by chipsm » Wed Sep 07, 2016 4:15 pm

I just updated the code. I actually added a Martix4 Button with the new code so I could do a comparison run.
WOW!
1177 ms vs 401 ms for 5000 records.
Great!
Could this get much better?

Thanks!
Clarence Martin
chipsm@themartinz.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Meeting Sept 1 2016

Post by FourthWorld » Wed Sep 07, 2016 4:44 pm

chipsm wrote:Could this get much better?!
If Mr. Kreisel shows up here we'll find out. :)

There are languages that can produce code that executes faster, but few that offer us as much choice between simple code or fast runtime.

Obviously it would be ideal if the engine could deliver both at the same time, but Computer Science suggests that won't be possible until the engine gets some deep AI, since optimization isn't just about the engine but the algorithms we ask it to perform. The more we think like developers using lower-level languages, the more we get performance on par with those.

But at least we have a choice. We can dive into a problem and get a useful result with minimal effort, solving the problem using very human-centric logic. And if we're working with large amounts of data where optimization can be useful, once we understand the problem well we can go back and think more like a computer to get a result that favors the processing limitations of computers.

This is one of the reasons I keep using LiveCode all these years: I can deliver a good result in minutes, and a great result in hours, but even then I'm usually spending less time coding than my friends using Java or C.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “SoCal LiveCode Group”