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 8848279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:23:19+00:00 2026-06-14T12:23:19+00:00

I recently built an app to test the speed difference between writing 100000 lines

  • 0

I recently built an app to test the speed difference between writing 100000 lines to a text file and 100000 inserts into a database

Here is the heart of the code

    private void RunTestBtn_Click(object sender, RoutedEventArgs e)
    {
        Stopwatch FFtimer = new Stopwatch();
        FFtimer.Start();
        RunFFTest();
        FFtimer.Stop();
        TimeSpan FFts = FFtimer.Elapsed;
        string FFelapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
        FFts.Hours, FFts.Minutes, FFts.Seconds,
        FFts.Milliseconds / 10);
        FFLabel.Content = "Flat File: " + FFelapsedTime;

        Stopwatch Datatimer = new Stopwatch();
        Datatimer.Start();
        DataFFTest();
        Datatimer.Stop();
        TimeSpan Datats = Datatimer.Elapsed;
        string DataelapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
        Datats.Hours, Datats.Minutes, Datats.Seconds,
        Datats.Milliseconds / 10);
        DBLabel.Content = "Database: " + DataelapsedTime;

    }
    void RunFFTest()
    {
        using(StreamWriter writer = new StreamWriter(@"F:\test\FFtest.txt"))
        {
            for(int i = 0; i< 100000; i++)
            {
            writer.WriteLine("test");
            }

        }
    }

    void DataFFTest()
    {
        using (SqlConnection conn = new SqlConnection("Data Source=EMMY;Initial Catalog=MyDB;User Id=SqlServiceUser;Password=MyPassword;"))
        {
            conn.Open();
            for (int i = 0; i < 100000; i++)
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO TestTable VALUES ('Test')";
                    cmd.ExecuteNonQuery();
                }
            }
        }

    }

The end result is that the Flat file writing took 1 millisecond and the sql inserts took nine minutes and forty one seconds. I know the database will take longer, but is there any way to speed this up?

  • 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-06-14T12:23:20+00:00Added an answer on June 14, 2026 at 12:23 pm

    Possible options …

    1. Use transactions (do multiple inserts per transaction)

    2. Use SqlBulkCopy API

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

Sidebar

Related Questions

The Problem: Until recently, I could build and test my app like normal. Now,
We recently built a web app using Prototype, making a fair amount of use
I have recently built an iPad app using PhoneGap. Currently it saves the last
I've recently built a reasonably complex database application for a university handling almost 200
I recently discovered you can compile JScript into console apps using a built in
I recently released a new version of my iPhone app that was built for
I recently ran into some issues this week on a web app that I
I recently built an AIR app using HTML, CSS and JavaScript. In the web
I am writing a small .NET Windows Forms app, and I use the built-in
I've recently pushed a Django app live. We built the app in a staging

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.