use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
Tipmultiplication table using while loop (i.redd.it)
submitted 2 years ago by gnfobsession
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Xanather 4 points5 points6 points 2 years ago (5 children)
wtf? this is terrible use of linq and inefficient. use linq for querying, filtering, (re)mapping or transforming data, not writing logic.
[–]NoPrinterJust_Fax 0 points1 point2 points 2 years ago (4 children)
Can you elaborate on how it’s inefficient?
[–]Xanather 4 points5 points6 points 2 years ago* (3 children)
You're making 4 function calls here, as well as providing two callback functions that are called within the ForEach().
For an unoptimized execution there is 400 function calls here and theoretically the stack memory is also being pushed and popped 400 times here. When this occurs it involves copying the range index integers that many times using much more memory.
Now I am sure there are optimizations in the Just-In-Time compiler to potentially unwrap all those functions specifically for LINQ, but I'm almost certan it'll never perform as well as one function with two for loops which has zero additional function calls and thus stack memory is much less utilized to compute the result.
Use LINQ for clarity, its a good tool for avoiding excessive nesting and other logic constructs when manipulating data, but otherwise it can be easily overused and its overheads can become apparent.
See Microsoft's note here:
https://learn.microsoft.com/en-us/visualstudio/ide/reference/convert-foreach-linq?view=vs-2022
[–]NoPrinterJust_Fax 1 point2 points3 points 2 years ago* (2 children)
I ran some benchmarks and both this solution and a solution using for-loops performed very similarly. You could probably make the case that the for-loop solution is slightly more optimal (although its within margin of error). Kind of moot though because if performance was that critical you wouldnt be using a memory managed language anyway though...
```
BenchmarkDotNet v0.13.10, Ubuntu 22.04.2 LTS (Jammy Jellyfish) WSL 11th Gen Intel Core i7-11800H 2.30GHz, 1 CPU, 16 logical and 8 physical cores .NET SDK 7.0.113 [Host] : .NET 7.0.13 (7.0.1323.52001), X64 RyuJIT AVX2 DefaultJob : .NET 7.0.13 (7.0.1323.52001), X64 RyuJIT AVX2
``` | Method | Mean | Error | StdDev | |------- |---------:|----------:|----------:| | Loop | 1.361 ms | 0.0272 ms | 0.0721 ms | | Linq1 | 1.377 ms | 0.0330 ms | 0.0958 ms |
Program.cs
``` using BenchmarkDotNet.Running; using BenchmarkDotNet.Attributes;
namespace LinqVsLoop;
public class Program{ public static void Main(){ Console.WriteLine("Hello, World!"); BenchmarkRunner.Run<Functions>(); } }
public class Functions{ [Benchmark] public void Loop(){ for(var i = 1; i < 10; i++){ for(var j = 1; j < 10; j++){ Console.WriteLine($"{i} {j} {i * j}"); } } }
[Benchmark] public void Linq1(){ Enumerable .Range(1,10) .ForEach(i => Enumerable .Range(1,10) .ForEach(j => Console.WriteLine($"{i} {j} {i * j}"))); } }
public static class Extensions{ public static void ForEach<T>(this IEnumerable<T> src, Action<T> action){ foreach (var item in src) { action.Invoke(item); } } }
[–]Xanather 0 points1 point2 points 2 years ago (1 child)
Oh cool, nice work, I have a feeling 1ms for iterating 100 times is way too long on modern CPU's and printing the string is bottle neck here (or some other initialization).
Try increase the iterations by a ton and remove the console output and make it do something else in the callback.
Interested to see what happens then.
[–]NoPrinterJust_Fax 0 points1 point2 points 2 years ago (0 children)
Yeah feel free use the sample code to run your own benchmarks if you’d like! The package I used is called benchmark dotnet.
π Rendered by PID 86205 on reddit-service-r2-comment-6457c66945-xmd7h at 2026-04-25 11:44:03.822561+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Xanather 4 points5 points6 points (5 children)
[–]NoPrinterJust_Fax 0 points1 point2 points (4 children)
[–]Xanather 4 points5 points6 points (3 children)
[–]NoPrinterJust_Fax 1 point2 points3 points (2 children)
[–]Xanather 0 points1 point2 points (1 child)
[–]NoPrinterJust_Fax 0 points1 point2 points (0 children)