Jump to content
Ascer

Set data to edit slow

Recommended Posts

Hello again,

I looking for fast possible way to insert single line to EditBox GuiCtrlCreateEdit.

BeginUpdate -> set data -> endUpdate cant be used!

#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $msg, $diff, $time, $hEdit
    GUICreate("My GUI", 400, 250)
    $hEdit = GUICtrlCreateEdit("", 0, 0, 400, 150)
    GUISetState()

    $time = TimerInit()
    For $i = 1 To 100
    GUICtrlSetData($hEdit, "GUICtrlSetData" & @CRLF, 1)
    Next
    $diff = Int(TimerDiff($time) * 100)/100
    GUICtrlCreateLabel("GUICtrlSetData: " & $diff & "ms", 10, 170)

    $time = TimerInit()
    For $i = 1 To 100
    GUICtrlSendMsg($hEdit, 0xC2, 0, "GUICtrlSendMsg $EM_REPLACESEL" & @CRLF)
    Next
    $diff = Int(TimerDiff($time) * 100)/100
    GUICtrlCreateLabel("GUICtrlSendMsg: " & $diff & "ms", 10, 190)

    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd

EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
$time = TimerInit()
  For $i = 1 To 100
    ControlSetText ($hGUI, "", $hEdit, "ControlSetText" & @CRLF)
  Next
  $diff = Int(TimerDiff($time))
  GUICtrlCreateLabel("ControlSetText: " & $diff & "ms", 10, 210)

124ms :)

Share this post


Link to post
Share on other sites

Begin/End can be used!

Fair comparison:

___Example()

Func ___Example()
    Local $msg, $diff, $time, $hEdit
    GUICreate("My GUI", 400, 260)
    $hEdit = GUICtrlCreateEdit("", 0, 0, 400, 150)
    GUISetState()

    $time = TimerInit()
    _GUICtrlEdit_BeginUpdate($hEdit)
    For $i = 1 To 100
        GUICtrlSetData($hEdit, "GUICtrlSetData" & @CRLF, 1)
    Next
    _GUICtrlEdit_EndUpdate($hEdit)
    $diff = TimerDiff($time) / 100
    GUICtrlCreateLabel("Raw GUICtrlSetData: " & $diff & "ms", 10, 170)
    GUICtrlSetData($hEdit, "")      ; clear content

    $time = TimerInit()
    _GUICtrlEdit_BeginUpdate($hEdit)
    For $i = 1 To 100
        GUICtrlSetData($hEdit, "GUICtrlSetData" & @CRLF, 1)
    Next
    _GUICtrlEdit_EndUpdate($hEdit)
    $diff = TimerDiff($time) / 100
    GUICtrlCreateLabel("GUICtrlSetData with Begin/End: " & $diff & "ms", 10, 190)
    GUICtrlSetData($hEdit, "")      ; clear content

    $time = TimerInit()
    _GUICtrlEdit_BeginUpdate($hEdit)
    Local $s
    For $i = 1 To 100
        $s &= "GUICtrlSetData" & @CRLF
    Next
    GUICtrlSetData($hEdit, $s)
    _GUICtrlEdit_EndUpdate($hEdit)
    $diff = TimerDiff($time) / 100
    GUICtrlCreateLabel("Block GUICtrlSetData: " & $diff & "ms", 10, 210)
    GUICtrlSetData($hEdit, "")      ; clear content

    $time = TimerInit()
    For $i = 1 To 100
        GUICtrlSendMsg($hEdit, 0xC2, 0, "GUICtrlSendMsg $EM_REPLACESEL" & @CRLF)
    Next
    $diff = TimerDiff($time) / 100
    GUICtrlCreateLabel("GUICtrlSendMsg: " & $diff & "ms", 10, 230)

    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>___Example

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

@jchd

You make an huuuge mistake here:

$diff = TimerDiff($time) / 100

 

My goal is to make chat Console for TCP client so after adding new line script should fast as possible back to received message loop.

Share this post


Link to post
Share on other sites
Posted (edited)

Ok my previous was not exactly fair, but it is still the fastest :

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>

Example()

Func Example()
  Local $msg, $diff, $time
  Global $hGUI = GUICreate("My GUI", 400, 250)
  Global $hEdit = GUICtrlCreateEdit("", 0, 0, 400, 150)
  GUISetState()

  $time = TimerInit()
  For $i = 1 To 100
    GUICtrlSetData($hEdit, "GUICtrlSetData" & @CRLF, 1)
  Next
  $diff = int(TimerDiff($time))
  GUICtrlCreateLabel("GUICtrlSetData: " & $diff & "ms", 10, 170)

  $time = TimerInit()
  For $i = 1 To 100
    GUICtrlSendMsg($hEdit, 0xC2, 0, "GUICtrlSendMsg $EM_REPLACESEL" & @CRLF)
  Next
  $diff = Int(TimerDiff($time))
  GUICtrlCreateLabel("GUICtrlSendMsg: " & $diff & "ms", 10, 190)

  $time = TimerInit()
  For $i = 1 To 100
    AddText ("ControlSetText" & @CRLF)
  Next
  $diff = Int(TimerDiff($time))
  GUICtrlCreateLabel("ControlSetText: " & $diff & "ms", 10, 210)

  $time = TimerInit()
  For $i = 1 To 100
    _GUICtrlEdit_AppendText ($hEdit, "AppendText" & @CRLF)
  Next
  $diff = Int(TimerDiff($time))
  GUICtrlCreateLabel("AppendText: " & $diff & "ms", 10, 230)

  While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
  WEnd

EndFunc   ;==>Example

Func AddText ($sTxt)
  Local Static $sEditText
  $sEditText &= $sTxt
  ControlSetText ($hGUI, "", $hEdit, $sEditText)
EndFunc

So far...

Edited by Nine

Share this post


Link to post
Share on other sites

Guys make tests on this example is more realistic in my case. Try to speed up it.

Example()


Func Example()

    Local $hGUI, $hEdit, $hButton, $hLabel, $time, $diff

    $hGUI = GUICreate("Test", 500, 500)
    $hEdit = GUICtrlCreateEdit("", 10, 10, 400, 400, 2099200)
    $hButton = GUICtrlCreateButton("Add", 10, 450, 80, 30)
    $hLabel = GUICtrlCreateLabel("", 10, 420, 100, 20)

    GUISetState()

    For $i = 1 To 100
        GUICtrlSetData($hEdit, "Example add new line with some text bla bla bah" & @CRLF, 1)
    Next

    GUICtrlSendMsg($hEdit, 0xB1, 9999, 9999)

    While 1

        Switch GUIGetMsg()
            Case -3
                Exit
            Case $hButton
                $time = TimerInit()
                GUICtrlSetData($hEdit, "Example add new line with some text bla bla bah" & @CRLF, 1)
                $diff = TimerDiff($time)
                GUICtrlSetData($hLabel, "Time: " & Int($diff * 100)/ 100 & "ms")
        EndSwitch

    WEnd

EndFunc

 

Share this post


Link to post
Share on other sites
Posted (edited)

The bigger the buffer that holds data the longer it will take = make $hEdit smaller in size and notice a speed up

Edited by Deye

Share this post


Link to post
Share on other sites

You right but this not solve problem the editbox can't be small it should be almost full screen mode

Share this post


Link to post
Share on other sites
Posted (edited)
3 hours ago, Ascer said:

You make an huuuge mistake here:

Which "huge mistake" please?

That's the time in ms used for inserting a line and displaying it.

Your * 100 / 100 is a no-op.

And I'd say something like 2.2 ms (on my old PC) is perfectly negligible.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

If TimerDiff return value in ms then you use / 100 and value is for single insert instead of all 100 lines.

Share this post


Link to post
Share on other sites
3 hours ago, Ascer said:

after adding new line script should fast as possible back to received message loop

hmmm, so, single thread in a loop waiting for ... something. Delegate :) 
Use an IPC to populate the edit control, or, leave it for later when the loop idle for say, 100 ms. ;) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...