C
C#15mo ago
Grimsky.

❔ 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
Grimsky.
Grimsky.15mo ago
If someone is available, I can show him his screen share
JakenVeina
JakenVeina15mo ago
wat is there a question buried in there, somewhere?
Grimsky.
Grimsky.15mo ago
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
JakenVeina
JakenVeina15mo ago
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
Grimsky.
Grimsky.15mo ago
Le code est exactement pareil. pareil pour tout le reste , tout est totalement identique. So yes, suddenly yes, there are a lot of items
JakenVeina
JakenVeina15mo ago
in both scenarios? how many
Grimsky.
Grimsky.15mo ago
1300
JakenVeina
JakenVeina15mo ago
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
Grimsky.
Grimsky.15mo ago
If u want , i can make a screenshare
JakenVeina
JakenVeina15mo ago
triple-nested loops so, how much data are you ACTUALLY working with
Grimsky.
Grimsky.15mo ago
First loops : 100 item Second loop : 100 item Third Loops : 1300 effects totally (one item get 13 effects)
JakenVeina
JakenVeina15mo ago
that would be 130,000 but still not crazy oop, now there's a 4th inner loop how big is runes, generally?
cap5lut
cap5lut15mo ago
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)
Accord
Accord15mo ago
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.