Raised This Month: $51 Target: $400
 12% 

[ANY] SMObjects


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-24-2017 , 16:18   [ANY] SMObjects
Reply With Quote #1

SM Objects

Description:
Create psuedo-objects in SourceMod easily with very little cost. It's kind of like Neuro-Toxin's Dynamic in a way, but faster and without garbage collection/type conversion.

This is basically a StringMap.

Example Usage:
https://github.com/Headline22/SMObje.../Documentation

Include File:
https://github.com/Headline22/SMObje.../SMObjects.inc

Free free to open issues on the project's github below. Any comments and suggestions are welcome.

Contribute to the project on Github.



Download the extension here.

Last edited by headline; 07-26-2017 at 14:12.
headline is offline
Kinsi
Senior Member
Join Date: Apr 2013
Old 06-25-2017 , 22:50   Re: [ANY] SMObjects
Reply With Quote #2

This looks pretty neat actually. Definitely useful in the world of SM. You should / could possibly add a performance comparison of Dynamic vs this.

Do you think it would be somehow possible to store native arrays in this? I see that being useful.

Last edited by Kinsi; 06-25-2017 at 22:52.
Kinsi is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-26-2017 , 00:48   Re: [ANY] SMObjects
Reply With Quote #3

Quote:
Originally Posted by Kinsi View Post
This looks pretty neat actually. Definitely useful in the world of SM. You should / could possibly add a performance comparison of Dynamic vs this.
My testing method
  • OnPluginStart create 10,000 instances
  • Set integer values in all 10,000
  • Read integer values in all 10,000
  • Delete all instances

Results: SMObjects is 75% quicker than Dynamic in this test. However the speed difference between SMObjects and something like StringMaps would be more interesting as they probably would preform identically


SMObjects
Code:
Operation took 0.025890 seconds
[SM] Loaded plugin test.smx successfully.
L 06/25/2017 - 23:38:26: rcon from "XXX.XXX.XXX.XXX:41484": command "sm plugins load test"
More info



Dynamic
Code:
Operation took 0.106509 seconds
[SM] Loaded plugin test.smx successfully.
L 06/25/2017 - 23:44:14: rcon from "XXX.XXX.XXX.XXX:54779": command "sm plugins load test"
More info

Last edited by headline; 06-26-2017 at 00:52.
headline is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 06-26-2017 , 03:47   Re: [ANY] SMObjects
Reply With Quote #4

Very well written! Out of curiosity I profiled StringMap and my own JSONObject from REST in Pawn:

StringMap: Operation took 0.004668 seconds
JSONObject: Operation took 0.004813 seconds
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-26-2017 , 04:01   Re: [ANY] SMObjects
Reply With Quote #5

Quote:
Originally Posted by DJ Tsunami View Post
Very well written! Out of curiosity I profiled StringMap and my own JSONObject from REST in Pawn:

StringMap: Operation took 0.004668 seconds
JSONObject: Operation took 0.004813 seconds
Thank you!

With some help from Fyren, I've added support for storing arrays as well. Looks something like this

PHP Code:
Object obj = new Object();
int array[] = {12345};

obj.SetArray("array", array, sizeof(array));

...
//Now there's two ways to read out from Object, if you know the length then you can do this.
int array[5];
obj.GetArray("array", array, sizeof(array));

// Or if you don't know the length
int size obj.GetArraySize("array");
int[] array = new int[size];
obj.GetArray("array", array, size);

delete obj// please clean up 

Last edited by headline; 06-26-2017 at 04:20.
headline is offline
Kinsi
Senior Member
Join Date: Apr 2013
Old 06-26-2017 , 09:54   Re: [ANY] SMObjects
Reply With Quote #6

This is awesome. Thanks!
Kinsi is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-26-2017 , 13:48   Re: [ANY] SMObjects
Reply With Quote #7

Even though I don't write SourceMod plugins, I was always wondering why there wasn't a way for plugin-defined handle types. Even though this isn't exactly that, it's 1 step closer. Well done.

Last edited by klippy; 06-26-2017 at 13:48.
klippy is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-27-2017 , 00:56   Re: [ANY] SMObjects
Reply With Quote #8

Quote:
Originally Posted by Kinsi View Post
This is awesome. Thanks!
Quote:
Originally Posted by KliPPy View Post
Even though I don't write SourceMod plugins, I was always wondering why there wasn't a way for plugin-defined handle types. Even though this isn't exactly that, it's 1 step closer. Well done.
Thanks, guys. I didn't think anyone would care slightly about this, but because a few people are interested I've added support for linux. Visit the new builds page for the latest versions

Last edited by headline; 06-27-2017 at 00:56.
headline is offline
Kinsi
Senior Member
Join Date: Apr 2013
Old 06-27-2017 , 16:03   Re: [ANY] SMObjects
Reply With Quote #9

Not sure if my testing methodology is flawed, but SMObjects seems to be consistently slower than StringMaps:



Code:

PHP Code:
public void OnPluginStart() {
    
RequestFrame(Bench_StringMaps);
    
    
RequestFrame(Bench_SMObjects);
}

void Bench_StringMaps(int a) {
    
PrintToServer("");
    
PrintToServer("< Testing StringMaps >");
    
////////////////////////////////////////////////////////////
    
PrintToServer("Creating 10k StringMaps");
    
    
float startTime GetEngineTime();
    
    
StringMap theTrie = new StringMap();
    
    
StringMap tries[9999];
    
int ichar whatever[8]; float x;
    
    for(
09999i++)
        
tries[i] = new StringMap();
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Writing 100k integers into StringMap");
    
    
startTime GetEngineTime();
    
    for(
0100000i++)
        
theTrie.SetValue("int"i);
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Writing 100k floats into StringMap");
    
startTime GetEngineTime();
    
    for(
0.0100000.0+= 1.0)
        
theTrie.SetValue("float"x);
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Reading 100k floats from StringMap");
    
startTime GetEngineTime();
    
    for(
0100000i++)
        
theTrie.GetValue("float"x);
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Creating and disposing 10k empty StringMaps");
    
startTime GetEngineTime();
    
    for(
010000i++) {
        
StringMap SM = new StringMap();
        
        
CloseHandle(SM);
    }
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Disposing 10k float filled StringMaps (500)");
    
startTime GetEngineTime();
                
    for(
09999i++)
        for(
0500.0+= 1.0) {
            
IntToString(RoundFloat(x), whateversizeof(whatever));
            
            
tries[i].SetValue(whateverx);
        }
    
    
PrintToServer("Filling ==> %f"GetEngineTime() - startTime);
    
startTime GetEngineTime();
    
    for(
09999i++)
        
CloseHandle(tries[i]);
    
    
PrintToServer("Disposing ==> %f"GetEngineTime() - startTime);
    
    for(
09999i++)
        
tries[i] = new StringMap();
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Disposing 10k float filled StringMaps (2k)");
    
startTime GetEngineTime();
                
    for(
09999i++)
        for(
02000.0+= 1.0) {
            
IntToString(RoundFloat(x), whateversizeof(whatever));
            
            
tries[i].SetValue(whateverx);
        }
    
    
PrintToServer("Filling ==> %f"GetEngineTime() - startTime);
    
startTime GetEngineTime();
    
    for(
09999i++)
        
CloseHandle(tries[i]);
    
    
PrintToServer("Disposing ==> %f"GetEngineTime() - startTime);
}


void Bench_SMObjects(int a) {
    
PrintToServer("");
    
PrintToServer("< Testing SMObjects >");
    
////////////////////////////////////////////////////////////
    
PrintToServer("Creating 10k SMObjects");
    
    
float startTime GetEngineTime();
    
    
Object theTrie = new Object();
    
    
Object tries[9999];
    
int ichar whatever[8]; float x;
    
    for(
09999i++)
        
tries[i] = new Object();
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Writing 100k integers into SMObject");
    
    
startTime GetEngineTime();
    
    for(
0100000i++)
        
theTrie.SetInt("int"i);
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Writing 100k floats into SMObject");
    
startTime GetEngineTime();
    
    for(
0.0100000.0+= 1.0)
        
theTrie.SetFloat("float"x);
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Reading 100k floats from SMObject");
    
startTime GetEngineTime();
    
    for(
0100000i++)
        
theTrie.GetFloat("float");
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Creating and disposing 10k empty SMObjects");
    
startTime GetEngineTime();
    
    for(
010000i++) {
        
Object SM = new Object();
        
        
CloseHandle(SM);
    }
    
    
PrintToServer("==> %f"GetEngineTime() - startTime);
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Disposing 10k float filled SMObjects (500)");
    
startTime GetEngineTime();
                
    for(
09999i++)
        for(
0500.0+= 1.0) {
            
IntToString(RoundFloat(x), whateversizeof(whatever));
            
            
tries[i].SetFloat(whateverx);
        }
    
    
PrintToServer("Filling ==> %f"GetEngineTime() - startTime);
    
startTime GetEngineTime();
    
    for(
09999i++)
        
CloseHandle(tries[i]);
    
    
PrintToServer("Disposing ==> %f"GetEngineTime() - startTime);
    
    for(
09999i++)
        
tries[i] = new Object();
    
    
////////////////////////////////////////////////////////////
    
PrintToServer("Disposing 10k float filled SMObjects (2k)");
    
startTime GetEngineTime();
                
    for(
09999i++)
        for(
02000.0+= 1.0) {
            
IntToString(RoundFloat(x), whateversizeof(whatever));
            
            
tries[i].SetFloat(whateverx);
        }
    
    
PrintToServer("Filling ==> %f"GetEngineTime() - startTime);
    
startTime GetEngineTime();
    
    for(
09999i++)
        
CloseHandle(tries[i]);
    
    
PrintToServer("Disposing ==> %f"GetEngineTime() - startTime);

Kinsi is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-27-2017 , 16:37   Re: [ANY] SMObjects
Reply With Quote #10

Woah. SMObjects is disappointingly slower. I will run some more tests.

Can you add me on steam? I may need you to run something for me
headline is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode