C
C#2y 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.OP2y ago
If someone is available, I can show him his screen share
JakenVeina
JakenVeina2y ago
wat is there a question buried in there, somewhere?
Grimsky.
Grimsky.OP2y 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
JakenVeina2y 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.OP2y 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
JakenVeina2y ago
in both scenarios? how many
Grimsky.
Grimsky.OP2y ago
1300
JakenVeina
JakenVeina2y 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.OP2y ago
If u want , i can make a screenshare
JakenVeina
JakenVeina2y ago
triple-nested loops so, how much data are you ACTUALLY working with
Grimsky.
Grimsky.OP2y ago
First loops : 100 item Second loop : 100 item Third Loops : 1300 effects totally (one item get 13 effects)
JakenVeina
JakenVeina2y ago
that would be 130,000 but still not crazy oop, now there's a 4th inner loop how big is runes, generally?
cap5lut
cap5lut2y 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
Accord2y 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.
Want results from more Discord servers?
Add your server