Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #39068 > unrolled thread

Doing what you suggest, the timing for function calls using setInterval is just awful slow why?????

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2020-10-31 13:26 -0700
Last post2020-11-01 16:19 -0800
Articles 20 on this page of 35 — 6 participants

Back to article view | Back to comp.lang.javascript


Contents

  Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:26 -0700
    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:37 -0700
      Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:41 -0700
    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:54 -0700
    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 17:51 -0700
      Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? luserdroog <luser.droog@gmail.com> - 2020-10-31 23:43 -0700
        Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 00:18 -0700
          Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 13:47 +0100
            Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:11 -0800
            Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:15 -0800
              Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:21 -0800
                Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-01 09:52 -0800
                  Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 11:27 -0800
                    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 11:33 -0800
                    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-01 15:42 -0800
                      Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-11-08 23:36 +0100
                      Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Silvio <silvio@internet.com> - 2020-11-09 17:01 +0100
                  Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 11:37 -0800
                Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 21:17 +0100
                  Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 14:08 -0800
                    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 01:09 +0100
              Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 21:09 +0100
                Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 14:07 -0800
                  Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 01:11 +0100
                    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 16:18 -0800
                      Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 11:37 +0100
            Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:28 -0800
              Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 21:22 +0100
                Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 14:10 -0800
                  Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 01:04 +0100
                    Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 16:16 -0800
                      Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 11:40 +0100
                        Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-11 00:21 -0800
                          Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-11 09:13 -0800
                  Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-01 16:19 -0800

Page 1 of 2  [1] 2  Next page →


#39068 — Doing what you suggest, the timing for function calls using setInterval is just awful slow why?????

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-10-31 13:26 -0700
SubjectDoing what you suggest, the timing for function calls using setInterval is just awful slow why?????
Message-ID<5189ddb2-f717-40ed-8ab7-d58f84427d8eo@googlegroups.com>
<HTML>
<HEAD>
<script>
	
//Head = 1 Tail = 0
function Time() {
   j=0; streak=0; consecutive=0;
   document.getElementById("textout").value="***WAIT***\n";
   choice=document.getElementById("mychoice").value;
   	if (choice=="head"){
		tid = setInterval(runheads,0);	
	} else {
		tid = setInterval(runtails,0);	
    	}	   
}

function abortTime() {
  clearInterval(tid);
}

function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

function runheads(){
		myval=getRandomInt(2);
		if(myval==1){
              	     	consecutive=consecutive+1;
		} else {
			if (consecutive>streak){
				mytext="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
				streak=consecutive;
				document.getElementById("textout").value+=mytext;
				
			}
			consecutive=0;
		}
		j++;
}

function runtails(){
		myval=getRandomInt(2);
		if(myval==0){
                	consecutive=consecutive+1;
		} else {
			if (consecutive>streak){
				mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
				streak=consecutive;
		        	document.getElementById("textout").value+=mytext;
			}
			consecutive=0;
		}
		j++;
}

</script>
</HEAD>

<BODY BGCOLOR="YELLOW">
<h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
<B>CONSECUTIVE COIN FLOPS  | SELECT</B>
<select name="mychoice" id="mychoice">
  <option value="head">HEADS</option>
  <option value="tail">TAILS</option>
</select>
<BR>
<textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
<button onclick="Time()">START COINFLIP</button> <button onclick="abortTime()">STOP FLIP</button>
</BODY>
</HTML>

[toc] | [next] | [standalone]


#39069

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-10-31 13:37 -0700
Message-ID<60750945-03db-4348-8800-b0ebb99a1f73o@googlegroups.com>
In reply to#39068
Den lördag 31 oktober 2020 kl. 21:26:26 UTC+1 skrev Jonas Thörnvall:
> <HTML>
> <HEAD>
> <script>
> 	
> //Head = 1 Tail = 0
> function Time() {
>    j=0; streak=0; consecutive=0;
>    document.getElementById("textout").value="***WAIT***\n";
>    choice=document.getElementById("mychoice").value;
>    	if (choice=="head"){
> 		tid = setInterval(runheads,0);	
> 	} else {
> 		tid = setInterval(runtails,0);	
>     	}	   
> }
> 
> function abortTime() {
>   clearInterval(tid);
> }
> 
> function getRandomInt(max) {
>   return Math.floor(Math.random() * Math.floor(max));
> }
> 
> function runheads(){
> 		myval=getRandomInt(2);
> 		if(myval==1){
>               	     	consecutive=consecutive+1;
> 		} else {
> 			if (consecutive>streak){
> 				mytext="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
> 				streak=consecutive;
> 				document.getElementById("textout").value+=mytext;
> 				
> 			}
> 			consecutive=0;
> 		}
> 		j++;
> }
> 
> function runtails(){
> 		myval=getRandomInt(2);
> 		if(myval==0){
>                 	consecutive=consecutive+1;
> 		} else {
> 			if (consecutive>streak){
> 				mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
> 				streak=consecutive;
> 		        	document.getElementById("textout").value+=mytext;
> 			}
> 			consecutive=0;
> 		}
> 		j++;
> }
> 
> </script>
> </HEAD>
> 
> <BODY BGCOLOR="YELLOW">
> <h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
> <B>CONSECUTIVE COIN FLOPS  | SELECT</B>
> <select name="mychoice" id="mychoice">
>   <option value="head">HEADS</option>
>   <option value="tail">TAILS</option>
> </select>
> <BR>
> <textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
> <button onclick="Time()">START COINFLIP</button> <button onclick="abortTime()">STOP FLIP</button>
> </BODY>
> </HTML>

It is just not usable end of story, my loop did a billion iteration in 20 seconds, this crappy solution manage to do some 2000-3000 iterated function calls.

It seem javascript just can't deal with this type of problem.

[toc] | [prev] | [next] | [standalone]


#39070

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-10-31 13:41 -0700
Message-ID<ddb0592a-1ffd-44f9-b683-dafa3fd6347eo@googlegroups.com>
In reply to#39069
Den lördag 31 oktober 2020 kl. 21:37:08 UTC+1 skrev Jonas Thörnvall:
> Den lördag 31 oktober 2020 kl. 21:26:26 UTC+1 skrev Jonas Thörnvall:
> > <HTML>
> > <HEAD>
> > <script>
> > 	
> > //Head = 1 Tail = 0
> > function Time() {
> >    j=0; streak=0; consecutive=0;
> >    document.getElementById("textout").value="***WAIT***\n";
> >    choice=document.getElementById("mychoice").value;
> >    	if (choice=="head"){
> > 		tid = setInterval(runheads,0);	
> > 	} else {
> > 		tid = setInterval(runtails,0);	
> >     	}	   
> > }
> > 
> > function abortTime() {
> >   clearInterval(tid);
> > }
> > 
> > function getRandomInt(max) {
> >   return Math.floor(Math.random() * Math.floor(max));
> > }
> > 
> > function runheads(){
> > 		myval=getRandomInt(2);
> > 		if(myval==1){
> >               	     	consecutive=consecutive+1;
> > 		} else {
> > 			if (consecutive>streak){
> > 				mytext="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
> > 				streak=consecutive;
> > 				document.getElementById("textout").value+=mytext;
> > 				
> > 			}
> > 			consecutive=0;
> > 		}
> > 		j++;
> > }
> > 
> > function runtails(){
> > 		myval=getRandomInt(2);
> > 		if(myval==0){
> >                 	consecutive=consecutive+1;
> > 		} else {
> > 			if (consecutive>streak){
> > 				mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
> > 				streak=consecutive;
> > 		        	document.getElementById("textout").value+=mytext;
> > 			}
> > 			consecutive=0;
> > 		}
> > 		j++;
> > }
> > 
> > </script>
> > </HEAD>
> > 
> > <BODY BGCOLOR="YELLOW">
> > <h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
> > <B>CONSECUTIVE COIN FLOPS  | SELECT</B>
> > <select name="mychoice" id="mychoice">
> >   <option value="head">HEADS</option>
> >   <option value="tail">TAILS</option>
> > </select>
> > <BR>
> > <textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
> > <button onclick="Time()">START COINFLIP</button> <button onclick="abortTime()">STOP FLIP</button>
> > </BODY>
> > </HTML>
> 
> It is just not usable end of story, my loop did a billion iteration in 20 seconds, this crappy solution manage to do some 2000-3000 iterated function calls.
> 
> It seem javascript just can't deal with this type of problem.

Probably could break out and doing all Math.random and write to array, but don't know if it is worth the effort.

[toc] | [prev] | [next] | [standalone]


#39071

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-10-31 13:54 -0700
Message-ID<7d20e42f-277c-4cfc-9e70-04024a6ea1dco@googlegroups.com>
In reply to#39068
Den lördag 31 oktober 2020 kl. 21:26:26 UTC+1 skrev Jonas Thörnvall:
> <HTML>
> <HEAD>
> <script>
> 	
> //Head = 1 Tail = 0
> function Time() {
>    j=0; streak=0; consecutive=0;
>    document.getElementById("textout").value="***WAIT***\n";
>    choice=document.getElementById("mychoice").value;
>    	if (choice=="head"){
> 		tid = setInterval(runheads,0);	
> 	} else {
> 		tid = setInterval(runtails,0);	
>     	}	   
> }
> 
> function abortTime() {
>   clearInterval(tid);
> }
> 
> function getRandomInt(max) {
>   return Math.floor(Math.random() * Math.floor(max));
> }
> 
> function runheads(){
> 		myval=getRandomInt(2);
> 		if(myval==1){
>               	     	consecutive=consecutive+1;
> 		} else {
> 			if (consecutive>streak){
> 				mytext="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
> 				streak=consecutive;
> 				document.getElementById("textout").value+=mytext;
> 				
> 			}
> 			consecutive=0;
> 		}
> 		j++;
> }
> 
> function runtails(){
> 		myval=getRandomInt(2);
> 		if(myval==0){
>                 	consecutive=consecutive+1;
> 		} else {
> 			if (consecutive>streak){
> 				mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
> 				streak=consecutive;
> 		        	document.getElementById("textout").value+=mytext;
> 			}
> 			consecutive=0;
> 		}
> 		j++;
> }
> 
> </script>
> </HEAD>
> 
> <BODY BGCOLOR="YELLOW">
> <h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
> <B>CONSECUTIVE COIN FLOPS  | SELECT</B>
> <select name="mychoice" id="mychoice">
>   <option value="head">HEADS</option>
>   <option value="tail">TAILS</option>
> </select>
> <BR>
> <textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
> <button onclick="Time()">START COINFLIP</button> <button onclick="abortTime()">STOP FLIP</button>
> </BODY>
> </HTML>

Is it possible to write anything recursive that breaks, that come anywhere near the loop speed?

<HTML>
<HEAD>
<script>
var run=false;


function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

//Head = 1 Tail = 0
function streaks(){
        var mytext="";
	var j=0;var streak=0;var consecutive=0;

	document.getElementById("textout").value="***WAIT***\n";
	choice=document.getElementById("mychoice").value;
	run=true;
	if (choice=="head"){
		while (j<1000000000){
		
			myval=getRandomInt(2);
			if(myval==1){
                   		consecutive=consecutive+1;
			} else {
				if (consecutive>streak){
					mytext+="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
					streak=consecutive;
		 		}
			consecutive=0;
			}
		j++;
		}
	} else if (choice=="tail"){
		while (j<1000000000){
		
			myval=getRandomInt(2);
			if(myval==0){
                   		consecutive=consecutive+1;
			} else {
				
				if (consecutive>streak){
		  			mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
					streak=consecutive;
		        	}
			consecutive=0;
			}
		j++;
		}
	} 
	document.getElementById("textout").value=mytext;
}

function stop(){
run=false;
}
</script>
</HEAD>

<BODY BGCOLOR="YELLOW">
<h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
<B>CONSECUTIVE COIN FLOPS  | SELECT</B>
<select name="mychoice" id="mychoice">
  <option value="head">HEADS</option>
  <option value="tail">TAILS</option>
</select>
<BR>
<textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
<button onclick="streaks()">START COINFLIP</button> <button onclick="stop()">STOP FLIP</button>
</BODY>
</HTML><HTML>
<HEAD>
<script>
var run=false;


function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

//Head = 1 Tail = 0
function streaks(){
        var mytext="";
	var j=0;var streak=0;var consecutive=0;

	document.getElementById("textout").value="***WAIT***\n";
	choice=document.getElementById("mychoice").value;
	run=true;
	if (choice=="head"){
		while (j<1000000000){
		
			myval=getRandomInt(2);
			if(myval==1){
                   		consecutive=consecutive+1;
			} else {
				if (consecutive>streak){
					mytext+="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
					streak=consecutive;
		 		}
			consecutive=0;
			}
		j++;
		}
	} else if (choice=="tail"){
		while (j<1000000000){
		
			myval=getRandomInt(2);
			if(myval==0){
                   		consecutive=consecutive+1;
			} else {
				
				if (consecutive>streak){
		  			mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
					streak=consecutive;
		        	}
			consecutive=0;
			}
		j++;
		}
	} 
	document.getElementById("textout").value=mytext;
}

function stop(){
run=false;
}
</script>
</HEAD>

<BODY BGCOLOR="YELLOW">
<h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
<B>CONSECUTIVE COIN FLOPS  | SELECT</B>
<select name="mychoice" id="mychoice">
  <option value="head">HEADS</option>
  <option value="tail">TAILS</option>
</select>
<BR>
<textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
<button onclick="streaks()">START COINFLIP</button> <button onclick="stop()">STOP FLIP</button>
</BODY>
</HTML>

[toc] | [prev] | [next] | [standalone]


#39072

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-10-31 17:51 -0700
Message-ID<f09c806b-ceff-4acb-b7f2-9d88dc46a26ao@googlegroups.com>
In reply to#39068
Den lördag 31 oktober 2020 kl. 21:26:26 UTC+1 skrev Jonas Thörnvall:
> <HTML>
> <HEAD>
> <script>
> 	
> //Head = 1 Tail = 0
> function Time() {
>    j=0; streak=0; consecutive=0;
>    document.getElementById("textout").value="***WAIT***\n";
>    choice=document.getElementById("mychoice").value;
>    	if (choice=="head"){
> 		tid = setInterval(runheads,0);	
> 	} else {
> 		tid = setInterval(runtails,0);	
>     	}	   
> }
> 
> function abortTime() {
>   clearInterval(tid);
> }
> 
> function getRandomInt(max) {
>   return Math.floor(Math.random() * Math.floor(max));
> }
> 
> function runheads(){
> 		myval=getRandomInt(2);
> 		if(myval==1){
>               	     	consecutive=consecutive+1;
> 		} else {
> 			if (consecutive>streak){
> 				mytext="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
> 				streak=consecutive;
> 				document.getElementById("textout").value+=mytext;
> 				
> 			}
> 			consecutive=0;
> 		}
> 		j++;
> }
> 
> function runtails(){
> 		myval=getRandomInt(2);
> 		if(myval==0){
>                 	consecutive=consecutive+1;
> 		} else {
> 			if (consecutive>streak){
> 				mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
> 				streak=consecutive;
> 		        	document.getElementById("textout").value+=mytext;
> 			}
> 			consecutive=0;
> 		}
> 		j++;
> }
> 
> </script>
> </HEAD>
> 
> <BODY BGCOLOR="YELLOW">
> <h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
> <B>CONSECUTIVE COIN FLOPS  | SELECT</B>
> <select name="mychoice" id="mychoice">
>   <option value="head">HEADS</option>
>   <option value="tail">TAILS</option>
> </select>
> <BR>
> <textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
> <button onclick="Time()">START COINFLIP</button> <button onclick="abortTime()">STOP FLIP</button>
> </BODY>
> </HTML>

Well i am done.
https://jonasth.github.io/random.html

[toc] | [prev] | [next] | [standalone]


#39073

Fromluserdroog <luser.droog@gmail.com>
Date2020-10-31 23:43 -0700
Message-ID<fd195b38-1147-4381-aa9d-0e70b291228fo@googlegroups.com>
In reply to#39072
On Saturday, October 31, 2020 at 7:51:30 PM UTC-5, Jonas Thörnvall wrote:

> Well i am done.
> https://jonasth.github.io/random.html

Did you figure out what the problem was?

[toc] | [prev] | [next] | [standalone]


#39074

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 00:18 -0700
Message-ID<2ed575bd-296e-43df-92ab-09265c196d8bo@googlegroups.com>
In reply to#39073
Den söndag 1 november 2020 kl. 07:43:43 UTC+1 skrev luserdroog:
> On Saturday, October 31, 2020 at 7:51:30 PM UTC-5, Jonas Thörnvall wrote:
> 
> > Well i am done.
> > https://jonasth.github.io/random.html
> 
> Did you figure out what the problem was?

Yeah Javascript is really not suited for handling UI updated in realtime. It simply not possible to run loops "stop them" and update the UI in realtime.

At least not in an efficient manner that make sense. Probably it should be possible to do in much more efficient way, by some polling technc. I can't simply see how setInterval can cause so much lag as it does.

[toc] | [prev] | [next] | [standalone]


#39077

FromArno Welzel <usenet@arnowelzel.de>
Date2020-11-01 13:47 +0100
Message-ID<i07p3eFk78kU1@mid.individual.net>
In reply to#39074
Jonas Thörnvall:

> Den söndag 1 november 2020 kl. 07:43:43 UTC+1 skrev luserdroog:
>> On Saturday, October 31, 2020 at 7:51:30 PM UTC-5, Jonas Thörnvall wrote:
>>
>>> Well i am done.
>>> https://jonasth.github.io/random.html
>>
>> Did you figure out what the problem was?
> 
> Yeah Javascript is really not suited for handling UI updated in realtime. It simply not possible to run loops "stop them" and update the UI in realtime.

No, it's just you who is not able to deal with it.

Example: <https://arnowelzel.de/en/projects/example-for-webgl>

How do you think are all games done using JavaScript and HTML5?

> At least not in an efficient manner that make sense. Probably it should be possible to do in much more efficient way, by some polling technc. I can't simply see how setInterval can cause so much lag as it does.

Define "lag". Depending on the capabilities of the browser and the
hardware used the example above renders an animation of a 3D model at
the exact refresh rate of your display. And this is all done in
JavaScript and as soon as one clicks and drags inside the animation it
stops and follows the mouse.


-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#39082

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 09:11 -0800
Message-ID<bf0e6383-0f41-488c-81ac-f07e117685c9o@googlegroups.com>
In reply to#39077
Den söndag 1 november 2020 kl. 13:47:52 UTC+1 skrev Arno Welzel:
> Jonas Thörnvall:
> 
> > Den söndag 1 november 2020 kl. 07:43:43 UTC+1 skrev luserdroog:
> >> On Saturday, October 31, 2020 at 7:51:30 PM UTC-5, Jonas Thörnvall wrote:
> >>
> >>> Well i am done.
> >>> https://jonasth.github.io/random.html
> >>
> >> Did you figure out what the problem was?
> > 
> > Yeah Javascript is really not suited for handling UI updated in realtime. It simply not possible to run loops "stop them" and update the UI in realtime.
> 
> No, it's just you who is not able to deal with it.
> 
> Example: <https://arnowelzel.de/en/projects/example-for-webgl>
> 
> How do you think are all games done using JavaScript and HTML5?
> 
> > At least not in an efficient manner that make sense. Probably it should be possible to do in much more efficient way, by some polling technc. I can't simply see how setInterval can cause so much lag as it does.
> 
> Define "lag". Depending on the capabilities of the browser and the
> hardware used the example above renders an animation of a 3D model at
> the exact refresh rate of your display. And this is all done in
> JavaScript and as soon as one clicks and drags inside the animation it
> stops and follows the mouse.
> 
> 
> -- 
> Arno Welzel
> https://arnowelzel.de

Well i guess lag is some 1000-10000 times slower, when using setInterval to handle UI messaging then if just running loops. You know a process that normally take some 20 sec, one really do not want to wait some 1000-10000 times longer....

[toc] | [prev] | [next] | [standalone]


#39083

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 09:15 -0800
Message-ID<a91f9849-21a2-499e-abf5-15408b0d6dd2o@googlegroups.com>
In reply to#39077
Den söndag 1 november 2020 kl. 13:47:52 UTC+1 skrev Arno Welzel:
> Jonas Thörnvall:
> 
> > Den söndag 1 november 2020 kl. 07:43:43 UTC+1 skrev luserdroog:
> >> On Saturday, October 31, 2020 at 7:51:30 PM UTC-5, Jonas Thörnvall wrote:
> >>
> >>> Well i am done.
> >>> https://jonasth.github.io/random.html
> >>
> >> Did you figure out what the problem was?
> > 
> > Yeah Javascript is really not suited for handling UI updated in realtime. It simply not possible to run loops "stop them" and update the UI in realtime.
> 
> No, it's just you who is not able to deal with it.
> 
> Example: <https://arnowelzel.de/en/projects/example-for-webgl>
> 
> How do you think are all games done using JavaScript and HTML5?
> 
> > At least not in an efficient manner that make sense. Probably it should be possible to do in much more efficient way, by some polling technc. I can't simply see how setInterval can cause so much lag as it does.
> 
> Define "lag". Depending on the capabilities of the browser and the
> hardware used the example above renders an animation of a 3D model at
> the exact refresh rate of your display. And this is all done in
> JavaScript and as soon as one clicks and drags inside the animation it
> stops and follows the mouse.

I am fully aware of Javascripts drawing/animation capabilities used it for a few projects.

That is not the problem, the problem is its capabilities when it come to poll values from the UI. It hogs the processor and makes running calculations some 1000 to 10 000 times slower. 

> -- 
> Arno Welzel
> https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#39084

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 09:21 -0800
Message-ID<88c8cc71-f3f5-44d0-8c26-144c09782636o@googlegroups.com>
In reply to#39083
Den söndag 1 november 2020 kl. 18:15:23 UTC+1 skrev Jonas Thörnvall:
> Den söndag 1 november 2020 kl. 13:47:52 UTC+1 skrev Arno Welzel:
> > Jonas Thörnvall:
> > 
> > > Den söndag 1 november 2020 kl. 07:43:43 UTC+1 skrev luserdroog:
> > >> On Saturday, October 31, 2020 at 7:51:30 PM UTC-5, Jonas Thörnvall wrote:
> > >>
> > >>> Well i am done.
> > >>> https://jonasth.github.io/random.html
> > >>
> > >> Did you figure out what the problem was?
> > > 
> > > Yeah Javascript is really not suited for handling UI updated in realtime. It simply not possible to run loops "stop them" and update the UI in realtime.
> > 
> > No, it's just you who is not able to deal with it.
> > 
> > Example: <https://arnowelzel.de/en/projects/example-for-webgl>
> > 
> > How do you think are all games done using JavaScript and HTML5?
> > 
> > > At least not in an efficient manner that make sense. Probably it should be possible to do in much more efficient way, by some polling technc. I can't simply see how setInterval can cause so much lag as it does.
> > 
> > Define "lag". Depending on the capabilities of the browser and the
> > hardware used the example above renders an animation of a 3D model at
> > the exact refresh rate of your display. And this is all done in
> > JavaScript and as soon as one clicks and drags inside the animation it
> > stops and follows the mouse.
> 
> I am fully aware of Javascripts drawing/animation capabilities used it for a few projects.
> 
> That is not the problem, the problem is its capabilities when it come to poll values from the UI. It hogs the processor and makes running calculations some 1000 to 10 000 times slower. 
> 
> > -- 
> > Arno Welzel
> > https://arnowelzel.de

Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop.

<HTML>
<HEAD>
<script>
        
//Head = 1 Tail = 0
function Time() {
   j=0; streak=0; consecutive=0;
   document.getElementById("textout").value="***WAIT***\n";
   choice=document.getElementById("mychoice").value;
           if (choice=="head"){
                tid = setInterval(runheads,0);        
        } else {
                tid = setInterval(runtails,0);        
            }          
}

function abortTime() {
  clearInterval(tid);
}

function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

function runheads(){
                myval=getRandomInt(2);
                if(myval==1){
                                   consecutive=consecutive+1;
                } else {
                        if (consecutive>streak){
                                mytext="NEW MAX AT FLIP "+j+" STREAK "+choice+" "+consecutive+"\n";
                                streak=consecutive;
                                document.getElementById("textout").value+=mytext;
                                
                        }
                        consecutive=0;
                }
                j++;
}

function runtails(){
                myval=getRandomInt(2);
                if(myval==0){
                        consecutive=consecutive+1;
                } else {
                        if (consecutive>streak){
                                mytext="Try "+j+" Consecutive "+choice+" "+consecutive+"\n";
                                streak=consecutive;
                                document.getElementById("textout").value+=mytext;
                        }
                        consecutive=0;
                }
                j++;
}

</script>
</HEAD>

<BODY BGCOLOR="YELLOW">
<h2>STATISTICAL OUTCOME **STREAKS** WHEN FLIPPING COINS</h2>
<B>CONSECUTIVE COIN FLOPS  | SELECT</B>
<select name="mychoice" id="mychoice">
  <option value="head">HEADS</option>
  <option value="tail">TAILS</option>
</select>
<BR>
<textarea id="textout" name="textout" rows="20" cols="50"></textarea><BR>
<button onclick="Time()">START COINFLIP</button> <button onclick="abortTime()">STOP FLIP</button>
</BODY>
</HTML>

[toc] | [prev] | [next] | [standalone]


#39087

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2020-11-01 09:52 -0800
Message-ID<4c9f166d-0d3a-42b1-9da3-0641286d658fn@googlegroups.com>
In reply to#39084
On Sunday, November 1, 2020 at 11:21:20 AM UTC-6, jonas.t...@gmail.com wrote:
> Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop.

If you're doing anything related to updating the UI, it's pointless to update it faster than the display would render it (generally 60 fps). Additionally setInterval/settimeout should not be set to '0'. The browser will clamp this value to 10 or 4:

<https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Delay_restrictions>
<https://humanwhocodes.com/blog/2011/12/14/timer-resolution-in-browsers/>

Also, given that the refresh rate of monitors are generally 60 fps that means 16ms. Using anything lower than that would be a waste of resources.

For updating the UI you should be using requestAnimationFrame instead:

<https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame>

[toc] | [prev] | [next] | [standalone]


#39088

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 11:27 -0800
Message-ID<4514994a-ea2e-4622-bdd0-9c786450fdb6o@googlegroups.com>
In reply to#39087
Den söndag 1 november 2020 kl. 18:52:39 UTC+1 skrev Michael Haufe (TNO):
> On Sunday, November 1, 2020 at 11:21:20 AM UTC-6, jonas.t...@gmail.com wrote:
> > Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop.
> 
> If you're doing anything related to updating the UI, it's pointless to update it faster than the display would render it (generally 60 fps). Additionally setInterval/settimeout should not be set to '0'. The browser will clamp this value to 10 or 4:
> 
> <https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Delay_restrictions>
> <https://humanwhocodes.com/blog/2011/12/14/timer-resolution-in-browsers/>
> 
> Also, given that the refresh rate of monitors are generally 60 fps that means 16ms. Using anything lower than that would be a waste of resources.
> 
> For updating the UI you should be using requestAnimationFrame instead:
> 
> <https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame>

What about sending to form DOM?, is that just futile? And what about polling stop button it also ude the DOM?

To me the javascript approach somehow seem backwards when using boolean while loops one shoud be able to specify how often to poll checking for UI writing to canvas or do stuff outside loop.

I guess it would be sort of a break statement, either passed as loop parameter, or some timer in a break clause, when it go out of loop poll values.

break(15){}

That it simply a timer attached to the boolean loop and breaks in this case every 15 millisec. I know i just throw out ideas that may not be connected to reality.

But i must ask how would you guys solve a computing intensive task, when you both need to check user UI for stop loop, write out values to form or canvas?

What is the basic approach to use for computing intensive realtime tasks?
It seem setInterval or setTimeout really not suitable for realtime updates of user interface weither it is canvas or writing or polling values from form or event handler.

[toc] | [prev] | [next] | [standalone]


#39089

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 11:33 -0800
Message-ID<3be53b25-41a1-4635-83a4-d9830e7bac26o@googlegroups.com>
In reply to#39088
Den söndag 1 november 2020 kl. 20:27:46 UTC+1 skrev Jonas Thörnvall:
> Den söndag 1 november 2020 kl. 18:52:39 UTC+1 skrev Michael Haufe (TNO):
> > On Sunday, November 1, 2020 at 11:21:20 AM UTC-6, jonas.t...@gmail.com wrote:
> > > Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop.
> > 
> > If you're doing anything related to updating the UI, it's pointless to update it faster than the display would render it (generally 60 fps). Additionally setInterval/settimeout should not be set to '0'. The browser will clamp this value to 10 or 4:
> > 
> > <https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Delay_restrictions>
> > <https://humanwhocodes.com/blog/2011/12/14/timer-resolution-in-browsers/>
> > 
> > Also, given that the refresh rate of monitors are generally 60 fps that means 16ms. Using anything lower than that would be a waste of resources.
> > 
> > For updating the UI you should be using requestAnimationFrame instead:
> > 
> > <https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame>
> 
> What about sending to form DOM?, is that just futile? And what about polling stop button it also ude the DOM?
> 
> To me the javascript approach somehow seem backwards when using boolean while loops one shoud be able to specify how often to poll checking for UI writing to canvas or do stuff outside loop.
> 
> I guess it would be sort of a break statement, either passed as loop parameter, or some timer in a break clause, when it go out of loop poll values.
> 
> break(15){}
> 
> That it simply a timer attached to the boolean loop and breaks in this case every 15 millisec. I know i just throw out ideas that may not be connected to reality.
> 
> But i must ask how would you guys solve a computing intensive task, when you both need to check user UI for stop loop, write out values to form or canvas?
> 
> What is the basic approach to use for computing intensive realtime tasks?
> It seem setInterval or setTimeout really not suitable for realtime updates of user interface weither it is canvas or writing or polling values from form or event handler.

The code i wrote using setInterval is straight forward, why don't you try fit it to something that generate streaks of coinflips effective. Or show me approach that generally could be used for "similar" computing intensive tasks.

For i think i would pick it up, if its really possible.

[toc] | [prev] | [next] | [standalone]


#39098

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2020-11-01 15:42 -0800
Message-ID<ba042418-06bb-4480-bddf-c45531ecb83fn@googlegroups.com>
In reply to#39088
On Sunday, November 1, 2020 at 1:27:46 PM UTC-6, jonas.t...@gmail.com wrote:
> Den söndag 1 november 2020 kl. 18:52:39 UTC+1 skrev Michael Haufe (TNO): 

> > For updating the UI you should be using requestAnimationFrame instead: 
> > 
> > <https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame>
> What about sending to form DOM?, is that just futile? And what about polling stop button it also ude the DOM? 

Instead of polling you use events:

```
function stop(e) { ... }
...
let btn = document.getElementById('myButton')
btn.addEventListener('click', stop)
```
 
> To me the javascript approach somehow seem backwards when using boolean while loops one shoud be able to specify how often to poll checking for UI writing to canvas or do stuff outside loop. 

It's better to maintain orthogonality [1]. Mixing timing constructs with looping constructs would be a poor design.


> But i must ask how would you guys solve a computing intensive task, when you both need to check user UI for stop loop, write out values to form or canvas? 

With event handlers like my example above.

> What is the basic approach to use for computing intensive realtime tasks? 

Minimize the amount of work being done. Minimize the number of steps and the amount of memory required.

> It seem setInterval or setTimeout really not suitable for realtime updates of user interface weither it is canvas or writing or polling values from form or event handler.

Correct. Use requestAnimationFrame. [2]

[1] <https://en.wikipedia.org/wiki/Orthogonality#Computer_science>
[2] <https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame>

[toc] | [prev] | [next] | [standalone]


#39125

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2020-11-08 23:36 +0100
Message-ID<5654398.lOV4Wx5bFT@PointedEars.de>
In reply to#39098
Michael Haufe (TNO) wrote:

> [1] <https://en.wikipedia.org/wiki/Orthogonality#Computer_science>

“Deleterious superfluities”.  I have to remember that *g*

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#39126

FromSilvio <silvio@internet.com>
Date2020-11-09 17:01 +0100
Message-ID<5fa967e3$0$8058$e4fe514c@newszilla.xs4all.nl>
In reply to#39098
On 11/2/20 12:42 AM, Michael Haufe (TNO) wrote:
> 
> It's better to maintain orthogonality [1]. Mixing timing constructs with looping constructs would be a poor design.
> 
> 

Orthogonality means that mixing (these) constructs produces logical and 
deducible behavior.

The mismatch is between loops depending on global state that needs to be 
manipulated by code outside the loop during loop execution. Single 
threaded asynchronous mode lacking fibers/coroutines of some kind can 
not express this in a straightforward way.

[toc] | [prev] | [next] | [standalone]


#39090

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 11:37 -0800
Message-ID<f4e339b0-da4c-429c-9c60-00d82a3db7ebo@googlegroups.com>
In reply to#39087
Den söndag 1 november 2020 kl. 18:52:39 UTC+1 skrev Michael Haufe (TNO):
> On Sunday, November 1, 2020 at 11:21:20 AM UTC-6, jonas.t...@gmail.com wrote:
> > Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop.
> 
> If you're doing anything related to updating the UI, it's pointless to update it faster than the display would render it (generally 60 fps). Additionally setInterval/settimeout should not be set to '0'. The browser will clamp this value to 10 or 4:

I don't know Michael isn't my problem the opposite i want to call the coin flipping function as fast as possible "with no delay".

Or are you saying i solve the problem backwards?
If so i do not get the solution calling event handler, canvas every x sec how the computer doing computations and to do that it will be in loop?

Show me how you think.


> 
> <https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Delay_restrictions>
> <https://humanwhocodes.com/blog/2011/12/14/timer-resolution-in-browsers/>
> 
> Also, given that the refresh rate of monitors are generally 60 fps that means 16ms. Using anything lower than that would be a waste of resources.
> 
> For updating the UI you should be using requestAnimationFrame instead:
> 
> <https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame>

[toc] | [prev] | [next] | [standalone]


#39093

FromArno Welzel <usenet@arnowelzel.de>
Date2020-11-01 21:17 +0100
Message-ID<i08jeiFplt9U1@mid.individual.net>
In reply to#39084
Jonas Thörnvall:

[...]
> Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop.

Why do you expect that setInterval() with 0 ms will cause code to run
with no delay at all?

Even with 0 ms there is overhead to trigger the interval handler. Of
course this is slower than just running something without any delay in a
loop.


-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#39096

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-11-01 14:08 -0800
Message-ID<bb71f895-9829-44ff-8df3-987a18d2ef73o@googlegroups.com>
In reply to#39093
Den söndag 1 november 2020 kl. 21:17:32 UTC+1 skrev Arno Welzel:
> Jonas Thörnvall:
> 
> [...]
> > Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop.
> 
> Why do you expect that setInterval() with 0 ms will cause code to run
> with no delay at all?
> 
> Even with 0 ms there is overhead to trigger the interval handler. Of
> course this is slower than just running something without any delay in a
> loop.
> 
> 
> -- 
> Arno Welzel
> https://arnowelzel.de

Yeah i could accept 100 times overhead, but not 1000-100 000 something is wrong.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web