Click here to Skip to main content
15,884,473 members
Articles / General Programming / Sorting

Fast List<String> Sort in C#

Rate me:
Please Sign up or sign in to vote.
4.62/5 (10 votes)
23 Aug 2012CPOL3 min read 88.1K   1.4K   46  
How to get faster sorting in List(T) string collections
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace SortTests
{
  public class ProcesserTime
  {
    private TimeSpan StartTime;
    private TimeSpan EndTime;
    private TimeSpan RunningTime;

    private Process _proc;

    public ProcesserTime(Process p)
    {
      _proc = p;
      StartTime = p.TotalProcessorTime;
    }

    public void StartNew()
    {
      RunningTime = TimeSpan.Zero;
      StartTime = _proc.TotalProcessorTime;
    }

    public void Stop()
    {
      EndTime = _proc.TotalProcessorTime;
      RunningTime += EndTime - StartTime;
    }

    public void Start()
    {
      StartTime = _proc.TotalProcessorTime;
    }

    public long ElapsedMilliseconds
    {
      get
      {
        return (long)(RunningTime.TotalMilliseconds);
      }
    }

    public long ElapsedTicks
    {
      get
      {
        return RunningTime.Ticks;
      }
    }

  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Delcan
United States United States
Dan Randolph is currently a Web Applications Developer with Delcan. Mr. Randolph has a B.S. dergee in Computer Science from the University of Wyoming. He is an active member of the Denver Visual Studio User Group. You can find him posting in the forums on [code.]msdn.microsoft.com and Code Project.

Comments and Discussions