Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
boytacean
Commits
fe23dd35
Verified
Commit
fe23dd35
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: more performance
parent
6615a795
No related branches found
No related tags found
1 merge request
!24
Performance optimisations
Pipeline
#2837
passed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontends/sdl/src/main.rs
+28
-44
28 additions, 44 deletions
frontends/sdl/src/main.rs
with
28 additions
and
44 deletions
frontends/sdl/src/main.rs
+
28
−
44
View file @
fe23dd35
...
...
@@ -39,23 +39,18 @@ const VOLUME: f32 = 64.0;
pub
struct
Benchmark
{
count
:
usize
,
chunk_size
:
Option
<
usize
>
,
cpu_only
:
Option
<
bool
>
,
}
impl
Benchmark
{
pub
fn
new
(
count
:
usize
,
chunk_size
:
Option
<
usize
>
,
cpu_only
:
Option
<
bool
>
)
->
Self
{
Self
{
count
,
chunk_size
,
cpu_only
,
}
pub
fn
new
(
count
:
usize
,
cpu_only
:
Option
<
bool
>
)
->
Self
{
Self
{
count
,
cpu_only
}
}
}
impl
Default
for
Benchmark
{
fn
default
()
->
Self
{
Self
::
new
(
50000000
,
None
,
None
)
Self
::
new
(
50000000
,
None
)
}
}
...
...
@@ -230,7 +225,6 @@ impl Emulator {
println!
(
"Going to run benchmark..."
);
let
count
=
params
.count
;
let
chunk_size
=
params
.chunk_size
.unwrap_or
(
1
);
let
cpu_only
=
params
.cpu_only
.unwrap_or
(
false
);
let
mut
cycles
=
0u64
;
...
...
@@ -240,14 +234,8 @@ impl Emulator {
let
initial
=
SystemTime
::
now
();
if
chunk_size
>
1
{
for
_
in
0
..
(
count
/
chunk_size
)
{
cycles
+=
self
.system
.clock_m
(
chunk_size
)
as
u64
;
}
}
else
{
for
_
in
0
..
count
{
cycles
+=
self
.system
.clock
()
as
u64
;
}
for
_
in
0
..
count
{
cycles
+=
self
.system
.clock
()
as
u64
;
}
let
delta
=
initial
.elapsed
()
.unwrap
()
.as_millis
()
as
f64
/
1000.0
;
...
...
@@ -503,7 +491,6 @@ impl Emulator {
pub
fn
run_benchmark
(
&
mut
self
,
params
:
&
Benchmark
)
{
let
count
=
params
.count
;
let
chunk_size
=
params
.chunk_size
.unwrap_or
(
1
);
let
cpu_only
=
params
.cpu_only
.unwrap_or
(
false
);
let
mut
cycles
=
0u64
;
...
...
@@ -513,14 +500,8 @@ impl Emulator {
let
initial
=
SystemTime
::
now
();
if
chunk_size
>
1
{
for
_
in
0
..
(
count
/
chunk_size
)
{
cycles
+=
self
.system
.clock_m
(
chunk_size
)
as
u64
;
}
}
else
{
for
_
in
0
..
count
{
cycles
+=
self
.system
.clock
()
as
u64
;
}
for
_
in
0
..
count
{
cycles
+=
self
.system
.clock
()
as
u64
;
}
let
delta
=
initial
.elapsed
()
.unwrap
()
.as_millis
()
as
f64
/
1000.0
;
...
...
@@ -690,6 +671,26 @@ struct Args {
rom_path
:
String
,
}
fn
run
(
args
:
Args
,
emulator
:
&
mut
Emulator
)
{
// determines if the emulator should run in headless mode or
// not and runs it accordingly, note that if running in headless
// mode the number of cycles to be run may be specified
if
args
.benchmark
{
emulator
.run_benchmark
(
&
Benchmark
::
new
(
args
.benchmark_count
,
Some
(
args
.benchmark_cpu
),
));
}
else
if
args
.headless
{
emulator
.run_headless
(
if
args
.cycles
>
0
{
Some
(
args
.cycles
)
}
else
{
None
});
}
else
{
emulator
.run
();
}
}
fn
main
()
{
// parses the provided command line arguments and uses them to
// obtain structured values
...
...
@@ -732,24 +733,7 @@ fn main() {
emulator
.load_rom
(
Some
(
&
args
.rom_path
));
emulator
.toggle_palette
();
// determines if the emulator should run in headless mode or
// not and runs it accordingly, note that if running in headless
// mode the number of cycles to be run may be specified
if
args
.benchmark
{
emulator
.run_benchmark
(
&
Benchmark
::
new
(
args
.benchmark_count
,
None
,
Some
(
args
.benchmark_cpu
),
));
}
else
if
args
.headless
{
emulator
.run_headless
(
if
args
.cycles
>
0
{
Some
(
args
.cycles
)
}
else
{
None
});
}
else
{
emulator
.run
();
}
run
(
args
,
&
mut
emulator
);
}
fn
build_device
(
device
:
&
str
)
->
Box
<
dyn
SerialDevice
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment