<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Optimize the loop to run faster in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713491#M89693</link>
    <description>&lt;P&gt;It works, Jarmo. Thanks a lot. You are awesome :)&lt;/img&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2024 22:36:27 GMT</pubDate>
    <dc:creator>Jackie_</dc:creator>
    <dc:date>2024-01-03T22:36:27Z</dc:date>
    <item>
      <title>Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713408#M89681</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Happy new year!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Is there a way to make the processing faster?&amp;nbsp;I tried using it &lt;STRONG&gt;for each&lt;/STRONG&gt;, and it did save&amp;nbsp;some time. I'm trying to figure out if I can optimize using the &lt;STRONG&gt;Column formula&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is my for loop. It takes a very long time to run over 1M iterations. Any advice?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For each();&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 16:22:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713408#M89681</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-01-04T16:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713469#M89685</link>
      <description>&lt;P&gt;What are you attempting to do?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 21:04:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713469#M89685</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-01-03T21:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713477#M89686</link>
      <description>&lt;P&gt;Have you tried the &lt;A href="https://www.jmp.com/support/help/en/17.0/#page/jmp/debug-or-profile-scripts.shtml#" target="_self"&gt;Profiler within Debugger&lt;/A&gt; to determine where most of the time is spent?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 21:23:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713477#M89686</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2024-01-03T21:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713478#M89687</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;For each&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 16:22:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713478#M89687</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-01-04T16:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713485#M89690</link>
      <description>&lt;P&gt;Here is the approach that I would take.&amp;nbsp; I simplified the code to make the approach more obvious.&amp;nbsp; On my system, each column is processed in 2.25 seconds or so.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
start = Tick Seconds();
dt &amp;lt;&amp;lt; Clear Row States;
dt &amp;lt;&amp;lt; Clear Column Selection();

dt &amp;lt;&amp;lt; Clear Column Selection;
allcol = dt &amp;lt;&amp;lt; get column names( string );
dt &amp;lt;&amp;lt; select column group( "Tests" );
selcol = dt &amp;lt;&amp;lt; get selected columns;
dt &amp;lt;&amp;lt; Clear Column Selection();

// loop thru each test, mark and count fails

//new for each loop
For Each( {ii, index}, selcol,
loopstart=tick seconds();
	If( ii &amp;lt;&amp;lt; get data type == "Numeric", 
	// set up pareto columns
		PassCol = New Column( "PassFail" || Char( index ), Numeric );
		colspec = ii &amp;lt;&amp;lt; get property( "spec limits" );
		lsl = colspec["LSL"];
		usl = colspec["USL"];
		dt &amp;lt;&amp;lt; select where( lsl &amp;gt;= ii &amp;lt;= usl );
		PassCol[dt &amp;lt;&amp;lt; get selected rows] = 1;
		dt &amp;lt;&amp;lt; invert row selection;
		PassCol[dt &amp;lt;&amp;lt; get selected rows] = 0;
	);
	show("loop " || char(index), tick seconds - loopstart);
);
show("total time= ", tick seconds()-start);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jan 2024 21:41:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713485#M89690</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-01-03T21:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713487#M89691</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;Thanks Jim. I tried your approach on 1 million rows, and it took ~3.5 mins&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jackie__0-1704319001399.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60166i473F527030E19DFC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jackie__0-1704319001399.png" alt="Jackie__0-1704319001399.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 21:58:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713487#M89691</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-01-03T21:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713488#M89692</link>
      <description>&lt;P&gt;Most likely I messed up matrix columns and rows at some point but I don't have time to fix them now and this isn't tested with larger dataset than the one provided&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$DOWNLOADS/Sample table.jmp", invisible);

dt &amp;lt;&amp;lt; Clear Row States;
dt &amp;lt;&amp;lt; Clear Column Selection;

cols = dt &amp;lt;&amp;lt; get column group("Tests");
test_cols = Transform Each({col}, cols, col &amp;lt;&amp;lt; get name);

testcol_count = N Items(test_cols);
FUDDnum = Round(testcol_count * 0.17);


get_specs = Function({dt, colname}, {Default Local},
	colspec = Column(dt, colname) &amp;lt;&amp;lt; get property("Spec Limits");
	
	specs = Associative Array();
	specs["LSL"] = Try(colspec["LSL"], .);
	specs["USL"] = Try(colspec["USL"], .);
	
	return(specs);
);

// set up pareto columns
yielditer = dt &amp;lt;&amp;lt; Get Table Variable("YieldIteration");
If(yielditer == "",
	yield_iter_num = 1;
,
	yield_iter_num = Num(yielditer) + 1;
);
dt &amp;lt;&amp;lt; Set Table Variable("YieldIteration", yield_iter_num);


NumFail = dt &amp;lt;&amp;lt; New Column("FailureNumber" || yielditer, Numeric, &amp;lt;&amp;lt;Set Each Value(0));
PassCol = dt &amp;lt;&amp;lt; New Column("PassFail" || yielditer, Numeric, &amp;lt;&amp;lt; Set Each Value());
ParetoCol = dt &amp;lt;&amp;lt; New Column("Pareto" || yielditer, Character, Nominal, Width(900),  &amp;lt;&amp;lt;Set Each Value("."));
dt &amp;lt;&amp;lt; Group Columns({PassCol, ParetoCol, NumFail});


// get failing cells
m = J(N Items(test_cols), N Rows(dt), 0);
For Each({testcol, idx}, test_cols,
	specs = get_specs(dt, testcol);
	fail_rows = Loc(dt[0, testcol] &amp;lt; specs["LSL"] | dt[0, testcol] &amp;gt; specs["USL"]);
	m[idx, fail_rows] = 1;
);

dt[0, NumFail &amp;lt;&amp;lt; get name] = V Sum(m)`;
dt[0, PassCol &amp;lt;&amp;lt; get name] = Not(V Sum(m)` &amp;gt; 0);

For Each Row(dt,
	failcount = Column(dt, (NumFail &amp;lt;&amp;lt; get name))[Row()];
	If(failcount &amp;gt; FUDDnum,
		ParetoCol[Row()] = "FUDD";
	, failcount &amp;gt; 0,
		fails = Loc(m[0, Row()]);
		ParetoCol[Row()] = Concat items(test_cols[fails], ", ");
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jan 2024 22:24:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713488#M89692</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-01-03T22:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize the loop to run faster</title>
      <link>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713491#M89693</link>
      <description>&lt;P&gt;It works, Jarmo. Thanks a lot. You are awesome :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 22:36:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Optimize-the-loop-to-run-faster/m-p/713491#M89693</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-01-03T22:36:27Z</dc:date>
    </item>
  </channel>
</rss>

