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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:44:49+00:00 2026-06-10T10:44:49+00:00

i did 2 basic tests 1- Create Procedure [dbo].[SetLoop] As Begin declare @counter int

  • 0

i did 2 basic tests

1-

Create Procedure [dbo].[SetLoop]
As Begin 
declare @counter int = 0 ,@a int,@b int,@c int,@d int,@e int
    While @counter < 1000000
    Begin
        set @a=1
        set @b=2
        set @c=3
        set @d=4
        set @e=5
        set @counter = @counter + 1
    End
End

create procedure SelectLoop
As Begin 
declare @counter int =0 ,@a int,@b int,@c int,@d int,@e int
    While @counter < 1000000
    Begin
        select @a=1, @b=2, @c=3, @d=4, @e=5,@counter = @counter + 1
    End
End

    var setTimes = new List<double>();
    for (var i = 0; i < 50; i++)
    {
        stopwatch.Start();
        dataContext.SetLoop();
        stopwatch.Stop();
        setTimes.Add(stopwatch.ElapsedMilliseconds);
        stopwatch.Reset();
    }

    var selectTimes = new List<double>();
    for (var i = 0; i < 50; i++)
    {
        stopwatch.Start();
        dataContext.SelectLoop();
        stopwatch.Stop();
        selectTimes.Add(stopwatch.ElapsedMilliseconds);
        stopwatch.Reset();
    }

    var setAverage = setTimes.Sum() / setTimes.Count;
    var selectAverage = selectTimes.Sum()/selectTimes.Count;

Results

setAverage : 2418.44
selectAverage : 1037.52

setAverage : 2513.8
selectAverage : 1025.98

setAverage : 2496.52
selectAverage : 996.36

results mean Select faster than Set by one and half time exactly by 142.78%


2-

    While @counter < 1000000
    Begin
        select @a=1
        select @b=2
        select @c=3
        select @d=4
        select @e=5
        select @counter = @counter + 1
    End

    While @counter < 1000000
    Begin
        set @a=1
        set @b=2
        set @c=3
        set @d=4
        set @e=5
        set @counter = @counter + 1
    End

Results

setAverage : 2518.58
selectAverage : 2504.44

setAverage : 2474.5
selectAverage : 2529.48

setAverage : 2511.22
selectAverage : 2514.04

results means they are the same

that’s mean if you need to set one variable prefer to use Select cuz in the future if
you want to set another one just ,@w=3 will be added but
if you want to set more than one variable defiantly you need to use Select
it’s easier to write, faster to be executed

But I was wondering why Select Faster than Set in the first test?

  • 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-10T10:44:50+00:00Added an answer on June 10, 2026 at 10:44 am

    It’s not (at least in the example you currently have), you are running 6 SET statements and a single SELECT statement for each iteration of the loop, therefore, I would expect the SELECT to be faster.

    I would suggest comparing like for like;

    CREATE Procedure [dbo].[SelectLoop]
    As Begin 
    declare @counter int = 0
        While @counter < 1000000
        Begin
            select @counter = @counter + 1
        End
    End
    
    CREATE Procedure [dbo].[SetLoop]
    As Begin 
    declare @counter int = 0
        While @counter < 1000000
        Begin
           set @counter = @counter + 1
        End
    End
    

    This will give a more accurate indication as to whether there are differences.

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

Sidebar

Related Questions

I need to create a prn file using java. Did a basic googling to
I did a basic Android project. I run it in eclipse with the AVD
I wanted to make a basic custom keypad for the iPhone , I did
Struggling with this one. I have set up a basic email/enquiry form for a
I have been struggling with this a while now. I implemented a basic IHttpHandler
I successfully installed and set it up searchlogic for basic (keyword) searching. I have
i did some tests with pre- and post-incrementation, to figure if there are performance
I need to create a really basic flash video (actionscript 2) where I click
New to C++; Basic understanding of includes, libraries and the compile process. Did a
I've been writing tests for a while now and I'm starting to get the

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.