performance

String of Digits Read in English

A popular task is to check if a string contains only digits. For example, you need to check if the user entered the correct phone number, index or a tax code of an organization. There are several ways to solve this task, which differ in their efficiency. Let's take a look at the most popular ones.

Read more...

Строка из чисел Читать на русском

Популярная задача — определить, состоит ли строка только из числовых символов. Например, нужно проверить, что пользователь правильно ввел номер телефона, индекс или ИНН организации. Сделать это можно несколькими способами, которые отличаются своей эффективностью. Давайте рассмотрим самые популярные из них.

Read more...

Any() vs Count: part 2 Read in English

In Part 1, we compared Any() and Count methods for different collections and proposed optimization approaches.

Read more...

Any() vs Count: часть 2 Читать на русском

В первой части мы сравнивали методы Any() и Count для различных коллекций и предложили вариант оптимизаций. Прошло достаточно времени, чтобы провести повторное сравнение.

Read more...

List initializer Read in English

We all used to type new List<int> { 1, 2, 3, 4 } or new int[] { 1, 2, 3, 4} to initialize collections with some values. It looks similar in syntax but differs in behavior, and you should be careful if you are concerned about performance.

Read more...

Harmful collection transformations. Part 3: collections Read in English

Starting with string in the first post we continue to study examples with collection transformations and how they affect our applications.

Read more...

Harmful collection transformations. Part 1: string to array of chars Read in English

An array - the simplest collection. It's just a memory block with elements of one type. Arrays are often used when we need to iterate a collection, to search elements or transform them. C# and .net evolved, many new collections were introduced, interfaces allowed to create generalized algorithms, LINQ simplified the work of programmers, but we continue to use arrays in inappropriate places and perform excess and sometimes harmful transformations. This post begins a series about collections, their features, performance and design. All posts will contain benchmarks, code examples, my opinion and recommendations.

I want to start with a string, some specific collection of .net.

Read more...

LINQ: Group by byte Read in English

LINQ is powerful tool for collection (or enumeration) operating. You use functional-like syntax for filtering, grouping, transforming data. All LINQ methods work with common interface IEnumerable<T> and usually methods do not check real type of collection, or data type. Sometimes, if you know the type of collection or generic type, you can optimize code for better performance (like in Any vs Count).

This article will show, how you can speed up grouping by specific key - byte.

Read more...

LINQ: Any() vs Count Читать на русском

Эта статья началась с обсуждения на Stack Overflow: Why LINQ method Any does not check Count?. Здесь мы сравним производительность методов Any и Count != 0.

Read more...

LINQ: Any vs Count Read in English

This post started from discussion on SO: Why LINQ method Any does not check Count? This article shows comparison of performance methods Any and Count = 0.

Read more...