Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up LinkedHashMap Remove() function from O(n) to O(1) #211

Closed
wants to merge 0 commits into from

Conversation

ErenDursun
Copy link

@ErenDursun ErenDursun commented Aug 24, 2022

This pull request speeds up the LinkedHashMap Remove() function from O(n) to O(1) and closes #178

benchmarks before changes

goos: linux
goarch: amd64
pkg: github.com/emirpasic/gods/maps/linkedhashmap
cpu: AMD Ryzen 7 5800H with Radeon Graphics         
BenchmarkTreeMapGet100-16          	  763164	      1542 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapGet1000-16         	   75256	     15810 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapGet10000-16        	    4922	    239738 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapGet100000-16       	     374	   3386053 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapPut100-16          	  292603	      3995 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapPut1000-16         	   22893	     50650 ns/op	    5952 B/op	     744 allocs/op
BenchmarkTreeMapPut10000-16        	    1977	    607819 ns/op	   77952 B/op	    9744 allocs/op
BenchmarkTreeMapPut100000-16       	     168	   6959023 ns/op	  797964 B/op	   99744 allocs/op
BenchmarkTreeMapRemove100-16       	 1513894	       793.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapRemove1000-16      	  146425	      7926 ns/op	      57 B/op	       0 allocs/op
BenchmarkTreeMapRemove10000-16     	    9826	    107367 ns/op	   84967 B/op	       1 allocs/op
BenchmarkTreeMapRemove100000-16    	       1	32919472200 ns/op	80403479216 B/op	  100201 allocs/op
PASS
ok  	github.com/emirpasic/gods/maps/linkedhashmap	51.908s

benchmarks after changes

goos: linux
goarch: amd64
pkg: github.com/emirpasic/gods/maps/linkedhashmap
cpu: AMD Ryzen 7 5800H with Radeon Graphics         
BenchmarkTreeMapGet100-16          	  778264	      1557 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapGet1000-16         	   73291	     15884 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapGet10000-16        	    4999	    242879 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapGet100000-16       	     368	   3280817 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapPut100-16          	  683550	      1707 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapPut1000-16         	   43914	     27164 ns/op	    5952 B/op	     744 allocs/op
BenchmarkTreeMapPut10000-16        	    3007	    398356 ns/op	   77952 B/op	    9744 allocs/op
BenchmarkTreeMapPut100000-16       	     234	   5150464 ns/op	  797956 B/op	   99744 allocs/op
BenchmarkTreeMapRemove100-16       	 1858681	       652.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapRemove1000-16      	  187239	      6481 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapRemove10000-16     	   18601	     65581 ns/op	       0 B/op	       0 allocs/op
BenchmarkTreeMapRemove100000-16    	    1670	    653730 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/emirpasic/gods/maps/linkedhashmap	17.348s

@sonarcloud
Copy link

sonarcloud bot commented Aug 24, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

1 similar comment
@sonarcloud
Copy link

sonarcloud bot commented Nov 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@n-event
Copy link

n-event commented Feb 17, 2023

Hi, any updates on this issue?

@ErenDursun ErenDursun force-pushed the master branch 2 times, most recently from fe09329 to 4e1358c Compare April 9, 2023 10:52
@sonarcloud
Copy link

sonarcloud bot commented Apr 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Speed up LinkedHashMap remove() function to O(1)
2 participants