Strings Are Evil

Contents

Context of the problem

Establishing a baseline

“MNO” is just a placeholder for the real value
Took: 8,750 ms
Allocated: 7,412,303 kb
Peak Working Set: 16,720 kb
Gen 0 collections: 1809
Gen 1 collections: 0
Gen 2 collections: 0

Easy win 1

Took: 6,922 ms
Allocated: 4,288,289 kb
Peak Working Set: 16,716 kb
Gen 0 collections: 1046
Gen 1 collections: 0
Gen 2 collections: 0

Easy win 2

Took: 8,375 ms
Allocated: 4,284,873 kb
Peak Working Set: 16,744 kb
Gen 0 collections: 1046
Gen 1 collections: 0
Gen 2 collections: 0

Splits are never cool

MNO,3,813496,36,30000,78.19,,
'MNO'
'3'
'813496'
'36'
'30000'
'78.19'
''
''
  • The length of each line is not fixed
  • The number of sections that are delimited by a comma are fixed
  • We only use the first three characters of each line to determine our interest in the line
  • This means there are five sections we are interested in but the section length is unknown
  • Sections do not change locations (e.g MNO is always the first section)
Took: 9,813 ms
Allocated: 6,727,664 kb
Peak Working Set: 16,872 kb
Gen 0 collections: 1642
Gen 1 collections: 0
Gen 2 collections: 0
Took: 9,125 ms
Allocated: 3,199,195 kb
Peak Working Set: 16,636 kb
Gen 0 collections: 781
Gen 1 collections: 0
Gen 2 collections: 0

Lists are not always nice

Took: 8,047 ms
Allocated: 2,650,318 kb
Peak Working Set: 16,560 kb
Gen 0 collections: 647
Gen 1 collections: 0
Gen 2 collections: 0
Took: 8,078 ms
Allocated: 2,454,297 kb
Peak Working Set: 16,548 kb
Gen 0 collections: 599
Gen 1 collections: 0
Gen 2 collections: 0

Pooling byte arrays

Took: 8,891 ms
Allocated: 2,258,272 kb
Peak Working Set: 16,752 kb
Gen 0 collections: 551
Gen 1 collections: 0
Gen 2 collections: 0

Goodbye StringBuilder

Took: 6,047 ms
Allocated: 1,160,856 kb
Peak Working Set: 16,816 kb
Gen 0 collections: 283
Gen 1 collections: 0
Gen 2 collections: 0

Skipping commas

  • Each section is preceded by a comma.
  • And that the location of each section within a line does not change.
Took: 5,703 ms
Allocated: 1,160,856 kb
Peak Working Set: 16,572 kb
Gen 0 collections: 283
Gen 1 collections: 0
Gen 2 collections: 0

The war between classes and structs

Took: 5,594 ms
Allocated: 768,803 kb
Peak Working Set: 16,512 kb
Gen 0 collections: 187
Gen 1 collections: 0
Gen 2 collections: 0

Goodbye StreamReader

Took: 5,594 ms
Allocated: 695,545 kb
Peak Working Set: 16,452 kb
Gen 0 collections: 169
Gen 1 collections: 0
Gen 2 collections: 0
Took: 6,781 ms
Allocated: 32 kb
Peak Working Set: 12,620 kb
Gen 0 collections: 0
Gen 1 collections: 0
Gen 2 collections: 0

TLDR — Give me a table

--

--

--

Software Engineer, UK

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Trials and Tribulations of HTML Newsletters

A glass pitcher of coffee is being poured into a white coffee mug that says “Ugh.”

How to write a compiler in Go: a quick guide

What is IP Address, Subnets, and CIDR Notation for Networking Introduction

Python list, tuple, and set.

Getting started using the new web console

https://medium.com/m/callback/email?token=176d3d4fed92&operation=register&state=medium&source=email-

KubeCon 2017, a report

6 examples of Industrial IoT monitoring solutions!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Indy Singh

Indy Singh

Software Engineer, UK

More from Medium

C# Partial Classes Explained

Git Theory And Branch concept

Variables In Code

Programming Foundations: Variables

Dautschun puppy peeking out of a box