I'm not quite sure what yours is doing, as I said previous in VS2019 I just wanted a label that clearly shows it counting from 0 to 100000 using a for loop then stopping with the time showing.
B4X:
private void CountUp()
{
var TimeElapsed = System.Diagnostics.Stopwatch.StartNew();
for (int i = 0; i <= 100000; i++)
{
label1.Text = Convert.ToString(i);
//label1.Invalidate();
//label1.Update(); //2.9 seconds faster
//label1.Refresh();//2.7 seconds faster
Application.DoEvents();
}
TimeElapsed.Stop();
Double Elapsed = TimeElapsed.ElapsedMilliseconds;
label2.Text = $"Time elapsed was {(Elapsed / 1000).ToString("F")}";
Console.WriteLine((Elapsed / 1000).ToString("#.##"));
}
Anyway it's lager time now, I've been working hard all day and I need a break from it all
Viewing the labels and seeing what was going one is what slows it down, without labels and using just the for loop with nothing in it, counting to 100000000 only takes 0.02 seconds in C#.
B4X:
//Code below takes 0.31 seconds with no labels
for (int i = 0; i <= 1000000000; i++)
{
}
If my memory serves me correctly, when I purchased my spare laptop to go abroad with 2 years ago, the processor was an i5-6300u which is a mobile processor. I'm presuming that you're using a desktop processor (but I could be wrong). I've not tested the speed on my i7 development laptop (it was encoding videos at the time), but obviously it would be much quicker especially as it's an i7 8th Gen and also 2 years newer.
But thank you for your feedback, I still want to know how you got 7 seconds though.
As was said in the first post, JavaFX appears to be a lot quicker.
B4X:
'B4J code was just
Sub CountUp
Dim StartTime As Long = DateTime.Now
For i = 0 To 100000
Label1.Text = i
Sleep(0)
Next
Label2.Text = $"Time elapsed = ${NumberFormat2((DateTime.Now - StartTime) / 1000, 1, 2, 2, False)} seconds"$
Log($"Time elapsed = ${NumberFormat2((DateTime.Now - StartTime) / 1000, 1, 2, 2, False)} seconds"$)
End Sub
Once again remove the labels and the results are basically instant.
If my memory serves me correctly, when I purchased my spare laptop to go abroad with 2 years ago, the processor was an i5-6300u which is a mobile processor. I'm presuming that you're using a desktop processor (but I could be wrong). I've not tested the speed on my i7 development laptop (it was encoding videos at the time), but obviously it would be much quicker especially as it's an i7 8th Gen and also 2 years newer.
But thank you for your feedback, I still want to know how you got 7 seconds though.
As was said in the first post, JavaFX appears to be a lot quicker.
Once again remove the labels and the results are basically instant.
yes i have a desktop processor.
with labels it take 10 seconds and without 3,5, so the 3,5 seconds waste is sleep(0)
B4X:
Sub CountUp
Dim StartTime As Long = DateTime.Now
For i = 0 To 100000
'Label1.Text = i
Sleep(0)
Next
'Label2.Text = $"Time elapsed = ${NumberFormat2((DateTime.Now - StartTime) / 1000, 1, 2, 2, False)} seconds"$
Log($"Time elapsed = ${NumberFormat2((DateTime.Now - StartTime) / 1000, 1, 2, 2, False)} seconds"$)
End Sub
7 seconds because i used a interval for doevents and write into the labels.
i know it was off topic
c#
B4X:
void Count() {
Console.WriteLine("Start");
var Start = DateTime.Now;
var dateStart = DateTime.Now;
TimeSpan diff;
for (int i = 0; i <= 10000000; i++)
{
diff = DateTime.Now - dateStart;
if (diff.TotalMilliseconds >= 250)
{
dateStart = DateTime.Now;
label1.Text = i.ToString("000,000,000");
//label1.Refresh();
Application.DoEvents();
}
}
label2.Text = (DateTime.Now - Start).TotalSeconds + " Sec.";
Console.WriteLine("Ready.");
}