View Full Version : Informational: Compare with Bool literal is SLOW!
StainlessS
1st November 2013, 00:59
Just for your information:
Have been playing with a script and found something that people might like to be aware of.
Comparing two bools is fast, but comparing if a bool is eg != False is SLOW.
Here tests on Int, Float, Bool, and String, 1 Million iterations on each type
# Req GScript & RT_Stats
NELS = 1000000 ERR = 0
GScript("""
# ############### Int ###############
vs=0 vg=0
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("INT: Compare Equality, Int variable against Int variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != 0) ? ERR + 1 : ERR
}
RT_DebugF("INT: Compare Equality, Int variable against Int literal 0 = %f seconds",RT_Timer()-START)
# ############### Float ###############
vs=0.0 vg=0.0
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("FLOAT: Compare Equality, Float variable against Float variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != 0.0) ? ERR + 1 : ERR
}
RT_DebugF("FLOAT: Compare Equality, Float variable against Float literal 0.0 = %f seconds",RT_Timer()-START)
# ############### Bool ###############
vs=False vg=False
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR # THIS WORKS FINE AND FAST
}
RT_DebugF("BOOL: Compare Equality, BOOL variable against BOOL variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs) ? ERR + 1 : ERR # THIS WORKS FINE AND FAST
}
RT_DebugF("BOOL: Test Truth status = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != False) ? ERR + 1 : ERR # VERY SLOW
}
RT_DebugF("BOOL: Compare Equality, BOOL variable against BOOL literal False = %f seconds",RT_Timer()-START)
# ############### String ###############
vs="" vg=""
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("STRING: Compare Equality, STRING variable against STRING variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != "") ? ERR + 1 : ERR
}
RT_DebugF("STRING: Compare Equality, STRING variable against STRING literal %c%c = %f seconds",34,34,RT_Timer()-START)
RT_DebugF("ERRORS = %d",ERR)
""")
colorbars()
Results on FULL and Empty plugins directories.
Plugins DIR FULL (~250 plugins)
00000005 5.87733173 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 4.078000 seconds
00000006 9.30669308 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.422000 seconds
00000007 13.37055683 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 4.063000 seconds
00000008 16.79634476 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.422000 seconds
00000009 20.82424355 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 4.031000 seconds
00000010 24.11998367 RT_DebugF: BOOL: Test Truth status = 3.296999 seconds
00000011 535.65899658 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 511.562012 seconds
00000012 539.84698486 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.187988 seconds
00000013 543.36889648 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.515015 seconds
00000014 543.36895752 RT_DebugF: ERRORS = 0
Plugins DIR EMPTY (GScript, Grunt, RT_Stats Only)
00000015 691.14471436 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 4.078000 seconds
00000016 694.57733154 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.437000 seconds
00000017 698.63641357 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 4.063000 seconds
00000018 702.07977295 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.437000 seconds
00000019 706.14385986 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 4.062999 seconds
00000020 709.44110107 RT_DebugF: BOOL: Test Truth status = 3.297001 seconds
00000021 851.28540039 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 141.858994 seconds
00000022 855.47912598 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.187012 seconds
00000023 859.00024414 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.515991 seconds
00000024 859.00036621 RT_DebugF: ERRORS = 0
It seems a rather heavy penalty
Gavino
1st November 2013, 01:13
Comparing two bools is fast, but comparing if a bool is eg != False is SLOW.
I guess that's because True and False are actually global script variables rather than literals built into the parser.
Surprising difference, but I seem to recall in an earlier test you discovered that name lookup is quite expensive.
Still, to keep it in perspective, it's probably insignificant compared to the cost of filtering frames.
StainlessS
1st November 2013, 01:31
insignificant compared to the cost of filtering frames
True, presumably then local vars are quite a bit faster to access than Global vars.
I thought it was worth pointing out anyway.
In the RT_Stats Array stuff, I've added timing to it and the dummy set/get vars and comparisons tests can take somewhat longer than the actual file array access.
Gavino
1st November 2013, 01:36
True, presumably then local vars are quite a bit faster to access than Global vars.
Yes, because a global lookup requires a local lookup first, since you can't tell at the start whether a variable is local or global.
Perhaps you could extend your timing test to include comparison with global vars of the different types.
StainlessS
1st November 2013, 01:44
OKEY DOKEY :)
But I think I'll try and up what Ive added to RT_Stats first.
Youka
1st November 2013, 04:02
Wow... color red isn't enough, these results have to be bold, underlined and whatelse this forum offers to highlight text ^^"
Shouldn't be ignored to fix, the difference is just huge!
StainlessS
1st November 2013, 04:42
Also added function level comparison.
Script Level:
NELS = 1000000 ERR = 0
GLOBAL_TEST = False # If True Tests Globals, else Locals
GScript("""
# ############### Int ###############
if(GLOBAL_TEST) { Global vs=0 Global vg=0 }
else { vs=0 vg=0 }
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("INT: Compare Equality, Int variable against Int variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != 0) ? ERR + 1 : ERR
}
RT_DebugF("INT: Compare Equality, Int variable against Int literal 0 = %f seconds",RT_Timer()-START)
# ############### Float ###############
if(GLOBAL_TEST) { Global vs=0.0 Global vg=0.0 }
else { vs=0.0 vg=0.0 }
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("FLOAT: Compare Equality, Float variable against Float variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != 0.0) ? ERR + 1 : ERR
}
RT_DebugF("FLOAT: Compare Equality, Float variable against Float literal 0.0 = %f seconds",RT_Timer()-START)
# ############### Bool ###############
if(GLOBAL_TEST) { Global vs=False Global vg=False }
else { vs=False vg=False }
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR # THIS WORKS FINE AND FAST
}
RT_DebugF("BOOL: Compare Equality, BOOL variable against BOOL variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs) ? ERR + 1 : ERR # THIS WORKS FINE AND FAST
}
RT_DebugF("BOOL: Test Truth status = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != False) ? ERR + 1 : ERR # VERY SLOW
}
RT_DebugF("BOOL: Compare Equality, BOOL variable against BOOL literal False = %f seconds",RT_Timer()-START)
# ############### String ###############
if(GLOBAL_TEST) { Global vs="" Global vg="" }
else { vs="" vg="" }
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("STRING: Compare Equality, STRING variable against STRING variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,NELS-1) {
ERR = (vs != "") ? ERR + 1 : ERR
}
RT_DebugF("STRING: Compare Equality, STRING variable against STRING literal %c%c = %f seconds",34,34,RT_Timer()-START)
RT_DebugF("ERRORS = %d",ERR)
""")
colorbars()
Function Level:
Function Test(int n, Bool GLB) {
ERR = 0
GScript("""
# ############### Int ###############
if(GLB) { Global vs=0 Global vg=0 }
else { vs=0 vg=0 }
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("INT: Compare Equality, Int variable against Int variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != 0) ? ERR + 1 : ERR
}
RT_DebugF("INT: Compare Equality, Int variable against Int literal 0 = %f seconds",RT_Timer()-START)
# ############### Float ###############
if(GLB) { Global vs=0.0 Global vg=0.0 }
else { vs=0.0 vg=0.0 }
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("FLOAT: Compare Equality, Float variable against Float variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != 0.0) ? ERR + 1 : ERR
}
RT_DebugF("FLOAT: Compare Equality, Float variable against Float literal 0.0 = %f seconds",RT_Timer()-START)
# ############### Bool ###############
if(GLB) { Global vs=False Global vg=False }
else { vs=False vg=False }
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != vg) ? ERR + 1 : ERR # THIS WORKS FINE AND FAST
}
RT_DebugF("BOOL: Compare Equality, BOOL variable against BOOL variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs) ? ERR + 1 : ERR # THIS WORKS FINE AND FAST
}
RT_DebugF("BOOL: Test Truth status = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != False) ? ERR + 1 : ERR # VERY SLOW
}
RT_DebugF("BOOL: Compare Equality, BOOL variable against BOOL literal False = %f seconds",RT_Timer()-START)
# ############### String ###############
if(GLB) { Global vs="" Global vg="" }
else { vs="" vg="" }
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != vg) ? ERR + 1 : ERR
}
RT_DebugF("STRING: Compare Equality, STRING variable against STRING variable = %f seconds",RT_Timer()-START)
START=RT_Timer()
For(i=0,n-1) {
ERR = (vs != "") ? ERR + 1 : ERR
}
RT_DebugF("STRING: Compare Equality, STRING variable against STRING literal %c%c = %f seconds",34,34,RT_Timer()-START)
RT_DebugF("ERRORS = %d",ERR)
""")
}
NELS = 1000000
Test(NELS,TRUE) # Global Vars
Test(NELS,False) # Global Vars Hidden by local ones
colorbars()
EMPTY Plugins DIR: Script Level GLOBAL
00000001 0.00000000 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 5.062000 seconds
00000002 3.82675982 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.828001 seconds
00000003 8.91532421 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 5.094000 seconds
00000004 12.73592663 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.811999 seconds
00000005 17.81522751 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 5.079000 seconds
00000006 21.49852562 RT_DebugF: BOOL: Test Truth status = 3.687000 seconds
00000007 162.19297791 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 140.703003 seconds
00000008 167.41950989 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 5.218994 seconds
00000009 171.39913940 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.984009 seconds
00000010 171.39921570 RT_DebugF: ERRORS = 0
EMPTY Plugins DIR: Script Level LOCAL
00000011 194.56706238 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 4.406000 seconds
00000012 198.36734009 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.797000 seconds
00000013 202.79896545 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 4.437000 seconds
00000014 206.60501099 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.797000 seconds
00000015 211.04505920 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 4.438000 seconds
00000016 214.70321655 RT_DebugF: BOOL: Test Truth status = 3.656000 seconds
00000017 355.40933228 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 140.703995 seconds
00000018 359.94030762 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.531006 seconds
00000019 363.86279297 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.921997 seconds
00000020 363.86288452 RT_DebugF: ERRORS = 0
Empty Plugins DIR: Function Level GLOBAL
00000001 0.00000000 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 4.718000 seconds
00000002 3.34956217 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.344000 seconds
00000003 8.03273582 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 4.688000 seconds
00000004 11.40571117 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.375000 seconds
00000005 16.09110451 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 4.687000 seconds
00000006 19.42492485 RT_DebugF: BOOL: Test Truth status = 3.327999 seconds
00000007 159.06101990 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 139.641006 seconds
00000008 163.89671326 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.827988 seconds
00000009 167.37376404 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.484009 seconds
00000010 167.37384033 RT_DebugF: ERRORS = 0
Empty Plugins DIR: Function Level LOCAL
00000011 171.32151794 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 3.953003 seconds
00000012 174.62376404 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.296997 seconds
00000013 178.57699585 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 3.953003 seconds
00000014 181.90570068 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.328995 seconds
00000015 185.87756348 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 3.968002 seconds
00000016 189.19720459 RT_DebugF: BOOL: Test Truth status = 3.328003 seconds
00000017 330.27294922 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 141.078995 seconds
00000018 334.38894653 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.109009 seconds
00000019 337.82855225 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.436981 seconds
00000020 337.82861328 RT_DebugF: ERRORS = 0
:::::::::::
Full Plugins(~250) DIR : Script Level GLOBAL
00000025 447.72695923 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 5.312000 seconds
00000026 451.69427490 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.969000 seconds
00000027 457.01705933 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 5.312000 seconds
00000028 460.97900391 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.969000 seconds
00000029 466.33081055 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 5.344000 seconds
00000030 470.16314697 RT_DebugF: BOOL: Test Truth status = 3.844000 seconds
00000031 1012.62829590 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 542.468018 seconds
00000032 1018.06005859 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 5.437988 seconds
00000033 1022.16326904 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 4.109009 seconds
00000034 1022.16333008 RT_DebugF: ERRORS = 0
Full Plugins(~250) DIR: Script Level LOCAL
00000039 1050.25549316 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 4.421000 seconds
00000040 1054.04235840 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.782000 seconds
00000041 1058.45349121 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 4.406000 seconds
00000042 1062.24829102 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.797000 seconds
00000043 1066.69824219 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 4.452999 seconds
00000044 1070.34411621 RT_DebugF: BOOL: Test Truth status = 3.641001 seconds
00000045 1613.36938477 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 543.046021 seconds
00000046 1617.88818359 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.515991 seconds
00000047 1621.80517578 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.921997 seconds
00000048 1621.80529785 RT_DebugF: ERRORS = 0
Full Plugins(~250) DIR: Function Level GLOBAL
00000025 386.96936035 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 4.687000 seconds
00000026 390.35235596 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.391000 seconds
00000027 395.05416870 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 4.703000 seconds
00000028 398.43664551 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.375000 seconds
00000029 403.12310791 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 4.687000 seconds
00000030 406.44921875 RT_DebugF: BOOL: Test Truth status = 3.327999 seconds
00000031 941.75195313 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 535.328979 seconds
00000032 946.54431152 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.781006 seconds
00000033 950.05017090 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.515015 seconds
00000034 950.05029297 RT_DebugF: ERRORS = 0
Full Plugins(~250) DIR: Function Level LOCAL
00000035 953.97119141 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 3.921997 seconds
00000036 957.26702881 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.296997 seconds
00000037 961.18847656 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 3.921997 seconds
00000038 964.49365234 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.296997 seconds
00000039 968.43902588 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 3.953003 seconds
00000040 971.75036621 RT_DebugF: BOOL: Test Truth status = 3.312988 seconds
00000041 1513.67224121 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 541.937012 seconds
00000042 1517.72277832 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.046997 seconds
00000043 1521.20629883 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.484009 seconds
00000044 1521.20642090 RT_DebugF: ERRORS = 0
EDIT: NOTE, Script level done on 2 separate runs, Function level 2 pass, Global 1st.
Curious, are variables stored in a name hashed list, or plain linked list ?
Gavino
1st November 2013, 10:49
Curious, are variables stored in a name hashed list, or plain linked list ?
Plain linked list, no hashing used.
It's interesting that comparison with a user global variable is only slightly slower than a local, but comparison with False is much slower. I think I can explain the difference. Try temporarily removing colors_rgb.avsi from the plugins folder - it declares a lot of global variables, which will come before False in the search order, but after any globals declared in the main script.
ultim
1st November 2013, 17:57
Avisynth+ has been using a hashlist for vars since its very first release.
StainlessS
1st November 2013, 22:12
Avisynth+ has been using a hashlist for vars since its very first release.
Glad to hear it. :)
Below full plugins DIR with all AVSI scripts removed.
The 3rd result set are same as first set Script level but with eg
ERR=(vs!=vg) ? ERR+1: ERR
converted to
(vs!=vg)
to remove the assignment and jump durations from the numbers.
Full Plugins(~250) DIR, NO AVSI: Script Level GLOBAL
00000005 7.20907497 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 5.265000 seconds
00000006 11.12597561 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.922000 seconds
00000007 16.42009163 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 5.297000 seconds
00000008 20.35220146 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.936999 seconds
00000009 25.66693306 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 5.313000 seconds
00000010 29.44991875 RT_DebugF: BOOL: Test Truth status = 3.781000 seconds
00000011 544.46820068 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 515.031006 seconds
00000012 549.90753174 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 5.453979 seconds
00000013 554.00189209 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 4.093018 seconds
00000014 554.00195313 RT_DebugF: ERRORS = 0
Full Plugins(~250) DIR, NO AVSI: Function Level GLOBAL
00000019 615.27874756 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 4.656000 seconds
00000020 618.57440186 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 3.297000 seconds
00000021 623.27581787 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 4.703000 seconds
00000022 626.64978027 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 3.375000 seconds
00000023 631.32452393 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 4.671999 seconds
00000024 634.63745117 RT_DebugF: BOOL: Test Truth status = 3.312000 seconds
00000025 1144.13696289 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 509.531006 seconds
00000026 1148.95190430 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 4.812988 seconds
00000027 1152.39428711 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 3.437012 seconds
00000028 1152.39440918 RT_DebugF: ERRORS = 0
Full Plugins(~250) DIR, NO AVSI: Script Level GLOBAL: Removed assignment and jump eg ERR=(vs!=vg) ? ERR+1:ERR becomes just (vs!=vg)
00000033 1294.06127930 RT_DebugF: INT: Compare Equality, Int variable against Int variable = 3.281000 seconds
00000034 1296.13549805 RT_DebugF: INT: Compare Equality, Int variable against Int literal 0 = 2.078000 seconds
00000035 1299.53149414 RT_DebugF: FLOAT: Compare Equality, Float variable against Float variable = 3.391000 seconds
00000036 1301.63537598 RT_DebugF: FLOAT: Compare Equality, Float variable against Float literal 0.0 = 2.109000 seconds
00000037 1304.89392090 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL variable = 3.266000 seconds
00000038 1306.94897461 RT_DebugF: BOOL: Test Truth status = 2.046000 seconds
00000039 1816.52307129 RT_DebugF: BOOL: Compare Equality, BOOL variable against BOOL literal False = 509.594025 seconds
00000040 1819.93298340 RT_DebugF: STRING: Compare Equality, STRING variable against STRING variable = 3.406006 seconds
00000041 1822.16638184 RT_DebugF: STRING: Compare Equality, STRING variable against STRING literal "" = 2.234985 seconds
Perhaps for some reason the parser is calling a new Eval() for the expression, guess that might explain such a time difference.
ultim
1st November 2013, 22:27
sry, wrong thread. nvm this post.
IanB
1st November 2013, 23:13
Many year ago Gzarkadas submitted a hashed implementation for the Var tables. At the time we had no GScript to quickly generate a million line script using For(i=0, 999999) so it was very difficult to find cases where the time wasted on linearly searching the Var tables could be compared with the time invested on a slightly more complicated hashed implementation. IIRC the result were for low numbers of Vars in play the linear search was slightly faster, for very high numbers of variables in play the hashed implementation was clearly faster, but the whole time spent in the process was only a few 100's of microseconds and that time was spent once only at compile time. It made no difference to the run time. Other project pressures to do a release were more pressing, so Klaus deferred it for a next version because of the poor return on developer time invested and it has until now fallen into the cracks. I thought hash tables were a good idea at the time, I still do.
So yes it takes ~500 microseconds to find the global variable "False" with many other global variables in play.
If it really matter, then you can promote the Global False to a local copy :-False=False # make a local Var
ColorBars()
Loop(100)
ConditionalFilter(last, last, "False", "==", "False")
Crop(0,0,16,8)The above runs at over 25000 fps, without the local it runs at 2000 fps
StainlessS
2nd November 2013, 00:14
Thank you for the history.
Had already considered False=False, but of course (!vs) [where vs == bool] would be better, had just used exact same comparisons for each type and that
was what revealed the duration differences.
I guess we now have the answer, as to why, thank you all :thanks:
ultim
2nd November 2013, 00:40
Many year ago Gzarkadas submitted a hashed implementation for the Var tables. At the time we had no GScript to quickly generate a million line script using For(i=0, 999999) so it was very difficult to find cases where the time wasted on linearly searching the Var tables could be compared with the time invested on a slightly more complicated hashed implementation. IIRC the result were for low numbers of Vars in play the linear search was slightly faster, for very high numbers of variables in play the hashed implementation was clearly faster, but the whole time spent in the process was only a few 100's of microseconds and that time was spent once only at compile time. It made no difference to the run time. Other project pressures to do a release were more pressing, so Klaus deferred it for a next version because of the poor return on developer time invested and it has until now fallen into the cracks. I thought hash tables were a good idea at the time, I still do.
Well my home-grown hashtable in Avs+ isn't perfect either. It has fixed size and if you have a lot of vars (more than about 1600-1700) all differently named, it's gonna break. So I'll either upgrade it to be able to resize itself, or I might just look into what Boost has to offer, since I'm linking to it now anyway. I guess this is even important enough to make it into the next release.
Mystery Keeper
2nd November 2013, 01:31
Well my home-grown hashtable in Avs+ isn't perfect either. It has fixed size and if you have a lot of vars (more than about 1600-1700) all differently named, it's gonna break. So I'll either upgrade it to be able to resize itself, or I might just look into what Boost has to offer, since I'm linking to it now anyway. I guess this is even important enough to make it into the next release.
Why don't you just use std::unordered_map?
TurboPascal7
2nd November 2013, 01:37
Why don't you just use std::unordered_map?
Because it's C++11, duh.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.