Page 1 of 2 12 LastLast
Results 1 to 40 of 42

Thread: Inline Functions

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Is there a way to make inline functions in VB?

  2. #2
    Guest
    What do you mean by "inline"? Built in functions?

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    Yeah, tell us that, anyone
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Personally, i do that by copying all the function code, but it sux, is there any automatic way to do this
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Guest
    You could add refrence to a DLL in your main project template and then when you load it, the DLL will be loaded as well.

  6. #6
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    VB needs Macros, like #define in C
    -Shickadance

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    we've got that
    Code:
    Const MYCONST = 12
    or are there other macros you can do in C

    I'm sure you can do inline functions in VB because I knew what they were before I learnt C++. I just can't remember how to do them

  8. #8
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    you can also do

    #define ADDER(A,B) A + B


    so if you have X = ADDER(4,5) it gets replaced by the preprocessor with X = 4 + 5.

    very sweet, esp. with redundant code and there is no function call overhead.
    -Shickadance

  9. #9
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    In VB there is #Const and #If..#ElseIf.. #End If which gets evaluated at compile time.
    -Shickadance

  10. #10
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    I had a look a while back for Inline functions in VB on the MSDN and found nothing, infact I found references to indicate that there was no such thing in VB.

    It can add a bit of speed in intensive loops but other than that they're not that important I wouldn't have thought.

    Question (Sorry, Sam, I know this is your thread)
    Is a function call within a form quicker than a function call to a module? or does it not make a difference?


    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    i'm going to test that paul, i've noticed functions called to modules are faster than to classes, especially if you have a heavy structure of classes. but i'm not sure about calling a class function inside itself
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    classes & Objects in VB have quite a bit over overhead, just remember, where possible try to dim a new object as the object type rather than "AS Object" it's a lot quicker if you're doing it a lot (like in linked lists)

    Let me know about your form / vs module tests,

    might try it may self so we can compare!

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  13. #13
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up

    I just tried it with Subs

    Form version, 1,000,000 calls = 0.45 sec
    Module version, 1,000,000 calls = 0.26 sec

    The sub was very simple, dim an Integer and add 1 to it.

    PLUS, for interest

    When I add a doevents into the loop after the sub, not in it)

    Form version, 1,000,000 calls = 9.65 sec
    Module version, 1,000,000 calls = 9.01 sec

    (All data averaged from three tries)

    in general, modules look quicker by about 0.2 - 0.5 sec per million calls,

    or 0.0000002 - 0.0000005 sec per call

    you wouldn't normally notice, unless you were looping the call millions of times.

    This also gives you an idea how how much inline functions would increase performance (if they existed)

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  14. #14
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    Paul was this compiled code or running from the VB IDE?
    -Shickadance

  15. #15
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    This was compiled for P6 on a win2k system
    PII 350 96mb RAM

    I tried it on compiled P5 and the difference was minor but then it doesn't really do anything, if there was more math in the sub then p6 may have made more of a difference.

    Might try it again at home, the system there is not only faster but cleaner, lot of **** cloging this NTFS system up.

    I imagine the results'll be similar.

    Would you like me to try it again in the IDE? not really any point I don't feel
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  16. #16
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    Nope. was just wondering.
    -Shickadance

  17. #17
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Talking

    Checking to see if I was an idiot?












    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  18. #18
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325

    Red face


    Damn! how did you figure that out? haha
    -Shickadance

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I did some test and i am a bit uncomfortable with the results with qwerryperformance counter
    The first test included 1000 single call procedures, all of them with a normal of 4.5µs each on my Athlon-600.

    This was what i was uncomfortable with, that i didn't get your results Paul, you probably included for next loops but uncluding them will just give errordiffusion
    The second test included for next loops with 1000 loops with 1000 calls. I got a 15% slower performance for the form calls
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  20. #20
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Use more loops, the difference between the call types will increase and if you run it several times you less likely to get CPU interference from the findfast and other processes that like to annoy.

    even if you're using that time ticks api you love so much 1000 loops is not enough, try 10,000,000 or 100mil! bring the difference into the world of seconds so that there can be no mistake, you can then see the difference for your self rather than rely on a time period you can't sense.

    I just use the Timer method! I don't rely on it to the 1000th of a second (or 100th if the cpu is overloaded) but it'll spot a half second delay to the 100th of a second ok




    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  21. #21
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Paul,

    How did you time the process if you did not have a doevents. The timer event will not fire unless you put a doevents somewhere?

    I just tried some tests like yours. Dim an integer and Add one to it. I called this 2,000,000

    With doevents it takes about 22 seconds.
    Without doevents it takes under a second.

    However if i do not have a doevents and run the loop 50,000,000 times the timer event never fires.
    Iain, thats with an i by the way!

  22. #22
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Exclamation

    something like this:

    Code:
    Dim MyLoop As Long
    Dim Timed As Single
    
    Timed = Timer
    
    For MyLoop = 1 to 1000000
    
        Call MySub()
    
    Next
    
    Label1.Caption = Str(Timer - Timed)
    
    Public Sub MySub()
    
        Dim X As Integer
        X = X + 1
    
    End Sub

    Have one button like that and another with a different named sub in a module. You can format the timer better than this but I'm typing this off the top of my head and I can't remember the params for the Format() function


    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  23. #23
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Oh I see what you mean now, You're using a timer control

    Lose it and use the code above. The Timer method captures the time as a single since midnight and places it in a variable, then when finished compare the current time to the variable, that way you don't have to worry about the CPU processors preventing an event from firing! (Unless your bios clock stops in which case you're screwed anyway )

    Look up "Timer" in the MSDN help

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  24. #24
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Paul,

    Nice one mate

    Got the same sort of results as you.

    The Module code took 0.44 seconds
    The Form code took 0.66 seconds

    I also tried it without explcitly declaring the variable as an integer, so it was a variant.

    The module then took 6.9 seconds
    The form then took 7 seconds

    Shows why it is not a good idea to use variants.
    Iain, thats with an i by the way!

  25. #25
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    WHAT! come on, Fox, have a look at this, they are using the timer function! WHoaa! That crappy function get's you a 60ms diffusion, with gettickcount you get 1ms, and querryperformance about 1µs!
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  26. #26
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    I did the same VB benchmarking with VB string operations, casting and passing byRef and byVal

    Here are some results from a P2-400 on NT4 compiled with VB6 SP3

    Ucase Benchmark 1,000,000x

    UCase: 2.94
    UCase$: 1.50
    UCaseF: 5.81 (This was an API call, someone said it was fast... haha)
    StrConv: 10.82

    Anyone wanna see more?
    -Shickadance

  27. #27
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    What is gettickcount? sounds perfect for what I need to do.

    and Timer is accurate to 10ms not 60ms. I have done a lot of research on this.
    -Shickadance

  28. #28
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Exclamation

    Timer! AAARGH!!! We need help here! Batman! Someone!

    *some minutes of meditation*

    Erm, about your Timer method: DO NOT USE THAT SILLY FUNCTION! *uh* "returns the number of seconds since midnight"... and it just updates each ~60 ms!!! How can you guys test such time-critical things with such a function???


    Ok, to be serious: Dont use the Timer function and dont use Timers unless youre coding something like a "please wait 5 seconds coz this is shareware" window
    I actually prefer the GetTickCount API call, kedaman QueryPerformance (which is the most precise)...

    But please, please dont use anything with Timer

  29. #29
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    A lot of research? MrShickadance, A lot of research without gettickcount? how do you do that?

    ARGH, we need Sam Finch! Explain to them, they can't do that with that crappy timer funcion!

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  30. #30

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    why is this my job? but no, the only reason I use timer is if I'm using random numbers and I go
    Code:
    Randomize Timer
    to make the randomness a bit more random.

    otherwise I use QueryPerformenceCounter, that works in microseconds and it's the most accurate thing on the computer.

  31. #31
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    kedaman.. a Digitizing Oscilloscope of course. I have to do time critical COM port sends and recieves.. the shortest wait time with Timer is 10ms, I am willing to put money on this!

    Sam if you just use Randomize() it's the same as Randomize(Timer)
    -Shickadance

  32. #32
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    hmmm, may be alot possible you're right but timer function and timer control uses the same timer function, how can it be possible that timer control updates in 60 ms? wouldn't be too sure, i'll go do some tests
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  33. #33
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Red face

    Yawn!!!

    I read that the timer control updates in multiples of 30ms and can be slower.

    who care's? This is not that time critical (otherwise, sure use GetTickCount) even if it's 60ms increments and my data is out by that much it's not a big deal in this case.

    Besides, you can just throw another magnitude of loops a your times become that much more accurate.

    I thought we were talking about process speeds, not timers anyway.

    (This is were everyone jumps down my throat for not trying to be accurate enough, I'll go and read up on the timer then and get back to you all)

    In the mean time, let's test some more performance issues, I like the idea earlier about testing data types, everyone here knows that a Long is faster than an Integer is faster than a single is faster than a double etc but how much faster? Wouldn't it be nice to have a lookup table!!! and what about the byte type? is it faster than an Integer?

    Shall we start a new thread on this? (and leave this one to the timer vs gettickcount debate??)



    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  34. #34
    Guest
    querryperformance about 1µs!
    It this is 1µs, then it's 1000 times faster than GetTickCount. Why doesn't everyone use this then?

  35. #35

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    queryperformance counter is a bit harder, and the accuracy variesfrom machine to machine.

  36. #36
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Time function (according to MS) is accurate to 1 vSecond (1/18th of a second) which is 0.05555... seconds

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  37. #37
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up

    Ok, here we go...

    Code:
    'Form Code
    
    Option Explicit
    
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    Private Sub Command1_Click()
    
        Dim Myloop As Long
        Dim sTime As Double
        Dim fTime As Double
        
        sTime = GetTickCount()
        
        For Myloop = 1 To 5000000
            Call FrmSub
        Next
        
        fTime = GetTickCount
        Label1.Caption = (fTime - sTime) / 1000
        
        
    End Sub
    
    Private Sub FrmSub()
    
        Dim x As Integer
        x = x + 1
    
    End Sub
    
    Private Sub Command2_Click()
    
        Dim Myloop As Long
        Dim sTime As Double
        Dim fTime As Double
        
        sTime = GetTickCount()
        
        For Myloop = 1 To 5000000
            Call ModSub
        Next
        
        fTime = GetTickCount
        Label1.Caption = (fTime - sTime) / 1000
        
    End Sub
    
    'Module Code
    
    Option Explicit
    
    Public Sub ModSub()
    
        Dim x As Integer
        x = x + 1
        
    End Sub
    Results
    Button1: 0.3, 0.31, 0.311, 0.31
    Button2: 0.2, 0.21, 0.2, 0.2

    Compiled version for P6, Same computer as before
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  38. #38
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Unhappy

    what happened to the code colouring in that last post ????????????????
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  39. #39
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    HEhe, such things happens. Happened to me many times. Ok, Well i did an app a while ago that tested different methods with different arguments, and i didn't have all types but it showed the querryperformance counter have some leaks in very short intervals, according to new tests with loops

    Paul while you're containing that For-loop in your counting, you get totally different results without, than without, so i'm not sure if they are reliable.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  40. #40
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    I'm starting a new project this weekend,

    Test the specs of functions, subs in same form , other form, mod etc

    then test data types and arrays of them

    It seems sensible to know when you're making trade-offs for maintainable / readable / modular code exactly what those trade-offs are in real terms.

    Basically build a performance app for.

    eg how much time do you loose for a class function?
    is it slower to call a property?

    I want all this in it.

    If you have any ideas of things to test/compare, let me know and I try to add it.

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width