Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 960703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:13:25+00:00 2026-05-16T01:13:25+00:00

For my own edification, I decided to test the comparative speeds of DataTable.ImportRow vs

  • 0

For my own edification, I decided to test the comparative speeds of DataTable.ImportRow vs DataTable.Merge. I found that DataTable.ImportRow was largely slower than DataTable.Merge. On rare occasion, the two functions had an equal processing time. On even rarer occasions, ImportRow was faster than Merge.

Below are my testing results and code.

  1. Why is ImportRow slower than Merge?
  2. What makes Merge faster?

alt text

    DataTable dt = new DataTable();

    dt.Columns.Add("customerId", typeof(int));
    dt.Columns.Add("username", typeof(string));

    for (int i = 0; i <= 100000; i++)
    {
        DataRow myNewRow;
        myNewRow = dt.NewRow();
        myNewRow["customerId"] = 1;
        myNewRow["username"] = "johndoe";
        dt.Rows.Add(myNewRow);
    }

    // First Duration
    DateTime startTime1 = DateTime.Now;

    DataTable dt2 = new DataTable();
    dt2 = dt.Clone();

    for (int i = 0; i < dt.Rows.Count; i++)
        dt2.ImportRow(dt.Rows[i]);

    DateTime stopTime1 = DateTime.Now;
    // End First Duration

    TimeSpan duration1 = stopTime1 - startTime1;

    // Second Duration
    DateTime startTime2 = DateTime.Now;

    DataTable dt3 = new DataTable();
    dt3 = dt.Clone();
    dt3.Merge(dt);

    DateTime stopTime2 = DateTime.Now;
    // End Second Duration

    TimeSpan duration2 = stopTime2 - startTime2;

Edit: Updated code as per suggestions –

    DataTable dt = new DataTable();

    dt.Columns.Add("customerId", typeof(int));
    dt.Columns.Add("username", typeof(string));

    DataColumn[] key = new DataColumn[1];

    key[0] = dt.Columns[0];

    dt.PrimaryKey = key;

    for (int i = 0; i <= 100000; i++)
    {
        DataRow myNewRow;
        myNewRow = dt.NewRow();
        myNewRow["customerId"] = i;
        myNewRow["username"] = "johndoe";
        dt.Rows.Add(myNewRow);
    }

    // First Duration
    //DateTime startTime1 = DateTime.Now;

    Stopwatch sw1 = new Stopwatch();
    sw1.Start();

    DataTable dt2 = new DataTable();
    dt2 = dt.Clone();

    for (int i = 0; i < dt.Rows.Count; i++)
        dt2.ImportRow(dt.Rows[i]);

    //DateTime stopTime1 = DateTime.Now;
    sw1.Stop();
    // End First Duration

    TimeSpan duration1 = sw1.Elapsed;

    // Second Duration
    //DateTime startTime2 = DateTime.Now;
    Stopwatch sw2 = new Stopwatch();

    sw2.Start();

    DataTable dt3 = new DataTable();
    dt3 = dt.Clone();
    dt3.Merge(dt);

    sw2.Stop();
    //DateTime stopTime2 = DateTime.Now;
    // End Second Duration

    TimeSpan duration2 = sw2.Elapsed;

    label3.Text = duration1.Milliseconds.ToString();
    label4.Text = duration2.Milliseconds.ToString();

alt text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:13:26+00:00Added an answer on May 16, 2026 at 1:13 am
    1. Your measured differences are quite small, especially since you have a resolution of only 20ms (DateTime). Use a StopWatch.

    2. You are setting Id=1 on all records, so it looks like you don’t have a proper primary key. That makes this very unrepresentative.

    3. Merge should be faster as that is the one that could be optimized for bulk actions. Given that, I find the results even more equal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own db class which has some purpose built functions that I
Mostly for my own edification I'm trying to list all of the global variables
I own a high traffic website that does business in the USA and Canada.
Background: I am writing a toy Lisp interperter/compiler in Haskell for my own amusement/edification.
I own a website and I wonder if there is a script that get
The answer provided here is a pretty awesome trick. Just for my own edification,
I've created my own ProfileUIViewController class that is a UINavigationControllerDelegate . I display this
I'd like to learn LAMP development for my own personal edification. I tried setting
I own a total of one iPhones. I want to test my app on
I own a website with 20 GB data on it Now I decided to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.