Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
C
ConcurrentSortedLinkedList
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamadbashar.disoki
ConcurrentSortedLinkedList
Commits
ce0771ef
Commit
ce0771ef
authored
May 10, 2023
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test time for different Sorted Linked List Implementations
parent
f7a214e2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
211 additions
and
29 deletions
+211
-29
workspace.xml
.idea/workspace.xml
+59
-25
README.MD
README.MD
+6
-2
AddThread.java
src/test/java/AddThread.java
+12
-0
ContainThread.java
src/test/java/ContainThread.java
+12
-0
RandomSeq.java
src/test/java/RandomSeq.java
+17
-0
RemoveThread.java
src/test/java/RemoveThread.java
+12
-0
SyncListTest.java
src/test/java/SyncListTest.java
+80
-2
TestThread.java
src/test/java/TestThread.java
+13
-0
No files found.
.idea/workspace.xml
View file @
ce0771ef
...
...
@@ -5,20 +5,14 @@
</component>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"3f4b2924-17d7-4794-bacf-d51c4f0be8bb"
name=
"Changes"
comment=
"Concurrent Sorted Linked List Implementations"
>
<change
afterPath=
"$PROJECT_DIR$/.gitignore"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/encodings.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/misc.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/uiDesigner.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/vcs.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/README.MD"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/pom.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/Entry.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/LockList.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/RWLockList.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/SortList.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/SyncList.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/SyncListTest.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/AddThread.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/ContainThread.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/RandomSeq.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/RemoveThread.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/TestThread.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/README.MD"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/README.MD"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/test/java/SyncListTest.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/test/java/SyncListTest.java"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
...
...
@@ -46,18 +40,27 @@
<option
name=
"hideEmptyMiddlePackages"
value=
"true"
/>
<option
name=
"showLibraryContents"
value=
"true"
/>
</component>
<component
name=
"PropertiesComponent"
>
<![CDATA[
{
"keyToString"
: {
"ASKED_ADD_EXTERNAL_FILES": "true"
,
"RunOnceActivity.OpenProjectViewOnStart": "true"
,
"RunOnceActivity.ShowReadmeOnStart": "true"
,
"SHARE_PROJECT_CONFIGURATION_FILES": "true"
,
"project.structure.last.edited": "Modules"
,
"project.structure.proportion": "0.0"
,
"project.structure.side.proportion": "0.0"
<component
name=
"PropertiesComponent"
>
{
"
keyToString
"
: {
"
ASKED_ADD_EXTERNAL_FILES
"
:
"
true
"
,
"
RunOnceActivity.OpenProjectViewOnStart
"
:
"
true
"
,
"
RunOnceActivity.ShowReadmeOnStart
"
:
"
true
"
,
"
SHARE_PROJECT_CONFIGURATION_FILES
"
:
"
true
"
,
"
project.structure.last.edited
"
:
"
Modules
"
,
"
project.structure.proportion
"
:
"
0.0
"
,
"
project.structure.side.proportion
"
:
"
0.0
"
}
}]]>
</component>
<component
name=
"RunManager"
>
}
</component>
<component
name=
"RunManager"
selected=
"JUnit.SyncListTest.testRun"
>
<configuration
name=
"SyncListTest"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"SortLinkedList"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"SyncListTest"
/>
<option
name=
"TEST_OBJECT"
value=
"class"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"SyncListTest.testAddList"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"SortLinkedList"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
...
...
@@ -68,8 +71,31 @@
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"SyncListTest.testRandSeq"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"SortLinkedList"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"SyncListTest"
/>
<option
name=
"METHOD_NAME"
value=
"testRandSeq"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"SyncListTest.testRun"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"SortLinkedList"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"SyncListTest"
/>
<option
name=
"METHOD_NAME"
value=
"testRun"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<recent_temporary>
<list>
<item
itemvalue=
"JUnit.SyncListTest.testRun"
/>
<item
itemvalue=
"JUnit.SyncListTest.testRandSeq"
/>
<item
itemvalue=
"JUnit.SyncListTest"
/>
<item
itemvalue=
"JUnit.SyncListTest.testAddList"
/>
</list>
</recent_temporary>
...
...
@@ -83,6 +109,14 @@
<option
name=
"presentableId"
value=
"Default"
/>
<updated>
1679470917075
</updated>
</task>
<task
id=
"LOCAL-00001"
summary=
"Concurrent Sorted Linked List Implementations"
>
<created>
1679492089742
</created>
<option
name=
"number"
value=
"00001"
/>
<option
name=
"presentableId"
value=
"LOCAL-00001"
/>
<option
name=
"project"
value=
"LOCAL"
/>
<updated>
1679492089742
</updated>
</task>
<option
name=
"localTasksCounter"
value=
"2"
/>
<servers
/>
</component>
<component
name=
"Vcs.Log.Tabs.Properties"
>
...
...
README.MD
View file @
ce0771ef
...
...
@@ -9,6 +9,10 @@
*
Structured Lock (synchronized).
*
Unstructured Lock (ReentrantLock, ReentrantReadWriteLock).
*
Test different implementations' performance.
*
Test time for different Sorted Linked List Implementations.
## TO-DO
*
Test throughput (operations per second) for different Sorted Linked List Implementations.
## Ref
[
Concurrent Programming in Java
](
https://www.coursera.org/learn/concurrent-programming-in-java/home/week/1
)
[
Locking Java
](
https://web.archive.org/web/20200809031812/http://www.ibm.com/developerworks/java/library/j-jtp10264
)
\ No newline at end of file
src/test/java/AddThread.java
0 → 100644
View file @
ce0771ef
public
class
AddThread
extends
TestThread
implements
Runnable
{
public
AddThread
(
RandomSeq
seq
,
int
seqPart
,
SortList
setList
)
{
super
(
seq
,
seqPart
,
setList
);
}
@Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++)
{
list
.
add
(
nums
[
i
]);
}
}
}
src/test/java/ContainThread.java
0 → 100644
View file @
ce0771ef
public
class
ContainThread
extends
TestThread
implements
Runnable
{
public
ContainThread
(
RandomSeq
seq
,
int
seqPart
,
SortList
setList
)
{
super
(
seq
,
seqPart
,
setList
);
}
@Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++)
{
list
.
contain
(
nums
[
i
]);
}
}
}
src/test/java/RandomSeq.java
0 → 100644
View file @
ce0771ef
import
java.util.Random
;
public
class
RandomSeq
{
int
seed
;
Random
random
;
int
maxNum
;
public
RandomSeq
(
int
setseed
,
int
setmaxNum
)
{
random
=
new
Random
(
setseed
);
this
.
seed
=
setseed
;
this
.
maxNum
=
setmaxNum
;
}
public
int
next
(){
return
random
.
nextInt
(
maxNum
);
}
}
src/test/java/RemoveThread.java
0 → 100644
View file @
ce0771ef
public
class
RemoveThread
extends
TestThread
implements
Runnable
{
public
RemoveThread
(
RandomSeq
seq
,
int
seqPart
,
SortList
setList
)
{
super
(
seq
,
seqPart
,
setList
);
}
@Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++)
{
list
.
remove
(
nums
[
i
]);
}
}
}
\ No newline at end of file
src/test/java/SyncListTest.java
View file @
ce0771ef
import
junit.framework.TestCase
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
SyncListTest
extends
TestCase
{
public
void
testAddList
(){
SyncList
syncList
=
new
SyncList
();
// syncList.remove(Integer.MAX_VALUE);
syncList
.
add
(
1
);
syncList
.
add
(
2
);
syncList
.
add
(
3
);
...
...
@@ -14,9 +17,84 @@ public class SyncListTest extends TestCase {
System
.
out
.
println
(
syncList
.
contain
(
5
));
System
.
out
.
println
(
syncList
.
contain
(
2
));
syncList
.
remove
(
3
);
}
public
void
testRandSeq
()
{
RandomSeq
randomSeq
=
new
RandomSeq
(
0
,
80_000
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
out
.
print
(
randomSeq
.
next
()
+
" "
);
}
}
int
randLen
=
20_000
;
public
void
testHelp
(
SortList
list
,
String
label
)
{
RandomSeq
seq
=
new
RandomSeq
(
0
,
80_000
);
List
<
Thread
>
addThreads
=
new
ArrayList
<>();
List
<
Thread
>
containThreads
=
new
ArrayList
<>();
List
<
Thread
>
removeThreads
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
AddThread
addThread
=
new
AddThread
(
seq
,
randLen
/
8
,
list
);
ContainThread
containThread
=
new
ContainThread
(
seq
,
randLen
/
8
,
list
);
RemoveThread
removeThread
=
new
RemoveThread
(
seq
,
randLen
/
8
,
list
);
Thread
threadA
=
new
Thread
(
addThread
);
addThreads
.
add
(
threadA
);
Thread
threadC
=
new
Thread
(
containThread
);
containThreads
.
add
(
threadC
);
Thread
threadR
=
new
Thread
(
removeThread
);
removeThreads
.
add
(
threadR
);
}
long
startA
=
System
.
currentTimeMillis
();
addThreads
.
stream
().
forEach
(
e
->
e
.
start
()
);
addThreads
.
stream
().
forEach
(
e
->
{
try
{
e
.
join
();
}
catch
(
InterruptedException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
});
long
endA
=
System
.
currentTimeMillis
()
-
startA
;
syncList
.
printList
(
);
System
.
out
.
println
(
"ADD "
+
label
+
" execution task: "
+
endA
+
" ms"
);
long
startC
=
System
.
currentTimeMillis
();
containThreads
.
stream
().
forEach
(
e
->
e
.
start
()
);
containThreads
.
stream
().
forEach
(
e
->
{
try
{
e
.
join
();
}
catch
(
InterruptedException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
});
long
endC
=
System
.
currentTimeMillis
()
-
startC
;
System
.
out
.
println
(
"Contain "
+
label
+
" execution task: "
+
endC
+
" ms"
);
long
startR
=
System
.
currentTimeMillis
();
removeThreads
.
stream
().
forEach
(
e
->
e
.
start
()
);
removeThreads
.
stream
().
forEach
(
e
->
{
try
{
e
.
join
();
}
catch
(
InterruptedException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
});
long
endR
=
System
.
currentTimeMillis
()
-
startR
;
System
.
out
.
println
(
"Remove "
+
label
+
" execution task: "
+
endR
+
" ms"
);
}
public
void
testRun
(){
SyncList
syncList
=
new
SyncList
();
testHelp
(
syncList
,
"Synchronization"
);
System
.
out
.
println
(
"=============="
);
RWLockList
rwLockList
=
new
RWLockList
();
testHelp
(
rwLockList
,
"RWLock"
);
System
.
out
.
println
(
"=============="
);
LockList
list
=
new
LockList
();
testHelp
(
list
,
"Lock"
);
}
}
src/test/java/TestThread.java
0 → 100644
View file @
ce0771ef
public
abstract
class
TestThread
{
SortList
list
;
Integer
[]
nums
;
public
TestThread
(
RandomSeq
seq
,
int
seqPart
,
SortList
setList
)
{
this
.
list
=
setList
;
this
.
nums
=
new
Integer
[
seqPart
];
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++){
nums
[
i
]
=
seq
.
next
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment