just for fun my c# counting in +1 steps + responsive somehow.
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("#.##"));
}
While doing a uLaw compression function for @Jmu5667, my first iteration was an inline Java version of https://stackoverflow.com/a/23603738. I then did a pure B4X version. Testing showed that the B4X version was just as fast and at times faster than the inline version. So at least in this one case, B4J speed matched or beat the Java implementation of an iterative code. B4X version of uLaw: https://www.b4x.com/android/forum/t...sion-code-available-to-all.96695/#post-612931Normally B4J speed is near Java speed. Isn't it?
at my pc it seems B4J is 2,5x faster that c# but i can't see if the label is really painted for each text assignment.I just wanted a label that clearly shows it counting from 0 to 100000 using a for loop then stopping with the time showing.
at my pc it seems B4J is 2,5x faster that c# but i can't see if the label is really painted for each text assignment.
//Code below takes 0.31 seconds with no labels
for (int i = 0; i <= 1000000000; i++)
{
}
your countup in c# was 25 seconds and in b4j it was 10 seconds.so in your case B4J was about 2.3 seconds???
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.your countup in c# was 25 seconds and in b4j it was 10 seconds.
'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
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.
Cheers...
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
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.");
}
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."); }