@Hosch250 That was my point. LINQ is lazily evaluated, so if you used .Where().Select on yours it would (probably) be slower than it would be if you used LINQ
@Hosch250 Hmm, I might be conflating memory consumption with performance here, but yours would definitely consume more memory eventually, and the effect would be exacerbated on larger lists
@Hosch250 But it doesn't, because you're allocating a new list multiple times (assuming you use Where and Select on the same target), you should only create a new list once if you're so worried about performance
@Hosch250 Do you have any info on the implementation of LINQ? can't seem to find it. I'm interested in learning as to why LINQ is so bad. My understanding based on preliminary googling is that it makes a LOT of heap allocations.
(Thanks, Rust, for helping me understand the difference :D)
it has to all be stored on the heap as well, @skiwi
inline twiddling can all be done on a stack for one
The specific note about LINQ in Roslyn is that it cannot be used in hot paths
It's not "You can't use at all", but "don't use this in things that run often" to avoid lots of heap allocations, which can trigger a large GC collection = DOOOOOOM
LINQ composes well and reads nicer than for loops (some stuff you can do with LINQ is seriously hairy code in normal C#) but that's about the only benefit it has going for it
Wait, the reflection-like stuff might have been the dynamic stuff that came in C# 4. I do remember that it does stuff to figure out the types, and stuff too.
The mission is to take 1,000,000 integers (0 to 999,999) and then for just filtering return the integers that are even, and for the select return double each integer.
I decided to take the functional approach in generating a string or random characters, so far I came up with this, it should perform better than boxing and then using a StringJoiner as collector:
Random random = new Random();
String randomString = IntStream.concat(
random.ints(8, 'a', 'z...
Doing the Where or Select in a raw loop body is the fastest every time. The Where provided by @Hosch250 is barely faster than the LINQ Where, and the Select provided is somewhat faster than the LINQ Select. When the provided are slower than the LINQ alternatives.
I'm working through Advent of Code 2016 in Rust. The prizes go to the swift, but I'm aiming for well-written code. This is Day 2.
To summarize the problem statement, given a newline-separated list of directions (e.g. "ULL\nRRDDD\nLURDL\nUUUUD\n"), move about on a 9-key keypad starting at 5, free...
I thought there would be a larger difference in memory allocation and those times, the differ only by a few milliseconds, I can imagine this matters mainly for compilers
@Mast Not in case of serious bugs .(An exception to that would be if a user wrote a comment saying that your code is completely broken, and needs to be fixed before it can be reviewed.) This is exactly what happened. — user10951082 hours ago
Custom class, with a string property. Randomly generated string objects, filtering outstring.Empty strings, and then for Select replacing all characters with different type of character.
One of these methods just got really slow...holy carp.
So I got bored and made a simple noughts and crosses game with colours instead of symbols.
The colours are red and blue and I made the GUI in NetBeans with my own code in combination with the NetBeans GUI Editor.
My Code:
package com.coal;
import java.util.Random;
public class Noughts exte...
@JeroenVannevel Now I got the tests passing by updating all the NuGet packages, but I can't run it live anymore:
> Warning AD1000 An instance of analyzer VSDiagnostics.Diagnostics.General.FieldCanBeReadonly.FieldCanBeReadonlyAnalyzer cannot be created from C:\USERS\HOSCH\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\14.0ROSLYN\EXTENSIONS\JEROEN\VSDIAGNOSTICS.VSIX\1.0\VSDiagnostics.dll: Could not load file or assembly 'System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I've just written up an answer for this question
Scattergories program
After scanning through the code and writing up my points to improve, I noticed that OP asked how to make that working as intended at all:
I would like to add a way to either check if a word is correct, or to suggest word...
I want to count the number of occurrences of all bigrams (pair of characters) in a file using C language. Bigram counts count the frequency of pairs of characters. Actually this is about Letter Frequencies. i implemented monogram, that was simple but i didn't find a solution related to bigrams. T...
ho can I improve my code ? Im new in swift and I want to know that I'm doing something wrong or harder way :). I make a simple war game app :D, names of variables aren't correct I know but I was doing it quickly and I didn't worry about names of var In that small project so I call them in English...
I created a TileMap-class to load tile sets, create and display tile maps. It is far from perfect so I want your opinions on how to improve it!
How it works: 1. Create TileMap object with "new TileMap( int tilesize )".
2. Create a tile set with "createSet( String path )" and specify the tile typ...
How would the Mapbox GL JS examples, such as (https://www.mapbox.com/mapbox-gl-js/example/filter-features-within-map-view/), be implemented using React?
When refactoring and old class in PHP, I noticed that it contained a lot of business logic and thus was not allowing code reuse. So I thought about composition in order to achieve horizontal code reuse (since inheritance permits only vertical reuse) and the possibility to do Dependency Injection ...
I've been coming over this question
unordered_multimap approach to adjacency list and graph search
which specifically asks about
I'm looking for suggestions on how to improve the usage of modern C++ features with this simple graph search algorithm, particularly with regard to the use of ST...
i really need a basic tic tac toe game. it should be very basic. just player vs player needed.i'm using Qt 5.6 and 5.7.
please help me in this.
i really need the game.
i would be very thankful.
I'm trying to make a (simple!) trajectory model of a missile that is launched from the surface in a certain angle. The missile applies force to go forward until it's fuel has run out. I thought I had it figured out right. But when I simulated some trajectories I found out that the angle with opti...
Here is my Field Can Be Made Readonly analyzer and quick fix. I would appreciate tips on how to improve my code, and on missed test cases.
First, the rules it works with:
It will only fire on private fields to make things simpler (fields in other scopes should be properties, anyway).
If the f...
Hello I have the following three lists, they have the same lenght and every element from a list as its corresponding value in the same position of the other lists:
for instance the label of the comment1 is 23 since is the first position of the list labels and it's corresponding user would be 899...
I'm voting to close this question as off-topic because "better" is opinion based. You might be able to adapt this into a question that would be on-topic for code review. — Quentin56 secs ago
There is another site on StackExchange, called CodeReview, to answer questions such as you have asked. — Scott Hunterjust now
Code Review is only appropriate if there's code (and the other conditions given in the Help Center there are met). This is too broad for SO as-asked, but it's not a fit for CR either. — Charles Duffy44 secs ago
I wrote a simple logger for a server I'm writing. Wondering if anyone has any suggestions to improve it.
doom_logger.erl
-module(doom_logger).
-author('Andrew McRobb').
-include("include/log_types.hrl").
-export([start/1, start/0, terminate/1, log/4, log/3, update_logger_state/3, get_local_ti...
How should my question look ? Do I've explained pretty much everything in the answer should I just put a link to it or rather copy paste it into my question's body ?
If the code works without any errors (hard to see, with such a huge dump), you can ask on Code Review. Make sure to read their guidelines first. — Rad Lexus21 secs ago
I've recently answered a question here.
This is my code :
public class TypeAccessor<T>
{
private readonly Func<T, T> m_applyDefaultValues;
private readonly Func<T> m_constructType;
public ReadOnlyCollection<string> CloneableProperties { get; }
public ReadOnlyDictionary<string...
The following code simulates a game of signals in which four participants (playing in pairs) show (muestra) and see (observan) signals. Signals are randomly assigned in the first round. Signals in the second round are assigned depending on a probability equation that takes into account memory dic...