Effect of Screen Updating

前端 未结 5 1718
梦谈多话
梦谈多话 2020-12-03 03:04

I have been playing around measuring code execution times to gauge differences between executing my scripts locally and on my server. At one point I forgot to disable

5条回答
  •  失恋的感觉
    2020-12-03 03:47

    Firstly I've been using the script written by Richie (UK) Post #7 Here

    It simply iterates through a loop changing the value of i in one cell. I have changed it slightly so it loops 10,000 times and I execute it 10 times for sample size.

    What is the effect of screen updating on the speed of my codes execution?

    These are the lengths of execution when Screen Updating was disabled and enabled:

    Disabled    Enabled
    0.61909653  2.105066913
    0.619555829 2.106865363
    0.620805767 2.106866315
    0.625528325 2.102403315
    0.625319976 2.0991179
    0.621287448 2.105103142
    0.621540236 2.101392665
    0.624537531 2.106866716
    0.620401789 2.109004449
    

    As you can see it takes almost 3.5 times as long to execute the code when Screen Updating is not disabled.

    Both of these codes were exceuted using the Run button in the VB editor, as opposed to 'watching' the spreadsheet.

    2 simple lines at the start and end of your code:

    Application.ScreenUpdating = False
    Application.ScreenUpdating = True
    

    But, they can have a large effect on the efficiency of your execution!

    Note: Obviously the advantages of Screen Updating will be well known to many here but this may be of benefit to beginners and I find it interesting to view the numbers!

提交回复
热议问题