SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 31/12/2017, 07:47 PM   #11
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,773
Reputation: 809
Default Re: unordered_map

Could you provide some benchmarks against foreach?
__________________

My GitHub:

Gammix is online now   Reply With Quote
Old 31/12/2017, 07:50 PM   #12
ShapeGaz
Little Clucker
 
Join Date: Sep 2017
Posts: 19
Reputation: 4
Default Re: unordered_map

Quote:
Originally Posted by Gammix View Post
Could you provide some benchmarks against foreach?
You mean speed test?
ShapeGaz is offline   Reply With Quote
Old 31/12/2017, 09:01 PM   #13
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,773
Reputation: 809
Default Re: unordered_map

Quote:
Originally Posted by ShapeGaz View Post
You mean speed test?
Yes.
__________________

My GitHub:

Gammix is online now   Reply With Quote
Old 01/01/2018, 12:28 AM   #14
ShapeGaz
Little Clucker
 
Join Date: Sep 2017
Posts: 19
Reputation: 4
Default Re: unordered_map

Plugin updated to version 0.4

- Added new types:
<string,string> = ss
<int,int> = ii
<string,int> = si
<int,string> = is

Example code:
PHP Code:
new map:map map_new_si();
map_emplace_si(map,"test",10);
new 
number map_find_si(map,"test");
if(
number != -1)
{
  
printf("Value: %d",number); // Outputs: Value: 10

Quote:
Originally Posted by Gammix View Post
Yes.
Speed test with foreach for 10k executings:
foreach: 475, 477, 479
unordered_map: 924, 933, 916

Speed test code

Last edited by ShapeGaz; 01/01/2018 at 08:13 AM.
ShapeGaz is offline   Reply With Quote
Old 01/01/2018, 08:13 AM   #15
ShapeGaz
Little Clucker
 
Join Date: Sep 2017
Posts: 19
Reputation: 4
Default Re: unordered_map

Speed test updated

Results:
foreach: 477, 480, 478
unordered_map: 1, 1, 2

Speed test code
ShapeGaz is offline   Reply With Quote
Old 01/01/2018, 11:11 AM   #16
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 867
Reputation: 295
Default Re: unordered_map

Quote:
Originally Posted by ShapeGaz View Post
Why you cannot use it like:
PHP Code:
 // Get int value
new map:map map_new();
map_emplace(map,"12","14");
new 
value[2];
map_find(map,"12",value,sizeof(value));
new 
intvalue strval(value);

// Emplace int value
new value[2];
format(value,sizeof(value),"%d",10); // With the key you can do the same
map_emplace(map,"test",value); 
1. I'll add to the next update
2. I'll add to the next update
3. What? Explain pls
because:
1. neater code
2. PAWN is slow

Instead of making 4 separate unordered maps, you could write a map interface template which would contain basic common functionalities and keep type dependent functions as virtual. This would avoid you having to duplicate a ton of code.

set_func1 - sets the value to the key; if the key does not exist, it creates it
set_func2 - sets the value to the key if and only if the key exists; if the key does not exist, does nothing and returns an error

Quote:
Originally Posted by Gammix View Post
Could you provide some benchmarks against foreach?
Foreach is going to be faster and it is not fair to compare foreach with this because they do not do the same thing.
Yashas is offline   Reply With Quote
Old 01/01/2018, 01:11 PM   #17
ShapeGaz
Little Clucker
 
Join Date: Sep 2017
Posts: 19
Reputation: 4
Default Re: unordered_map

Quote:
Originally Posted by Yashas View Post
Instead of making 4 separate unordered maps, you could write a map interface template which would contain basic common functionalities and keep type dependent functions as virtual. This would avoid you having to duplicate a ton of code.
Will be added to the next update

Quote:
Originally Posted by Yashas View Post
set_func1 - sets the value to the key; if the key does not exist, it creates it
set_func2 - sets the value to the key if and only if the key exists; if the key does not exist, does nothing and returns an error
Thanks i got it. I'll add to the next updates

Last edited by ShapeGaz; 01/01/2018 at 07:39 PM.
ShapeGaz is offline   Reply With Quote
Old 01/01/2018, 08:26 PM   #18
ShapeGaz
Little Clucker
 
Join Date: Sep 2017
Posts: 19
Reputation: 4
Default Re: unordered_map

Plugin updated to version 0.5

- Added new natives
- Changed syntax

First post updated
ShapeGaz is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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



All times are GMT. The time now is 12:30 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.