❔ C# Math.Min/Math.Floor & Foreach/for
Hello, so my problem is quite bizarre, I have two somewhat similar solutions, but my concern impacts a very precise code, this is the same for both projects, it is the execution of a for i , which will then retrieve some information and then do a foreach , this foreach will include several calculations, except that for the first project, all of this takes 1 second and for the second it takes 6 seconds.
This action runs 100 times.
15 Replies
If someone is available, I can show him his screen share
wat
is there a question buried in there, somewhere?
Ah sorry, I'm wondering if someone could help me find the cause of this. How come on one project it takes 0.5 seconds and the other takes 6 seconds.
@ReactiveVeina
ah
either you've written it differently, or there's a different volume of data
there is basically no calculation I can think of that should take you 6 seconds in .NET, unless you're iterating over millions or billions of items
Le code est exactement pareil. pareil pour tout le reste , tout est totalement identique.
So yes, suddenly yes, there are a lot of items
in both scenarios?
how many
1300
yeah, there is no reason that should take more than a few hundred milliseconds
let's see some code
or, let's just talk about what this data is, and what calculation you're trying to perform, and we can talk about the best way to get it done
If u want , i can make a screenshare
triple-nested loops
so, how much data are you ACTUALLY working with
First loops : 100 item
Second loop : 100 item
Third Loops : 1300 effects totally (one item get 13 effects)
that would be 130,000
but still not crazy
oop, now there's a 4th inner loop
how big is
runes
, generally?u should also reuse the instances if u can, eg u r creating a ton of stop watches, instead of just reusing one
same for the crypto random.
with that many iterations the
Console.WriteLine
overhead will probably be significant as well
composite formatting is probably slower than string interpolation as well,
so instead of Console.WriteLine("Time elapsed StopWatch 2: {0}", stopwatchs.Elapsed);
u should do Console.WriteLine($"Time elapsed StopWatch 2: {stopwatchs.Elapsed}");
(anyway the ton of writes to the console are probably the main reason why its that slow)Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.