measure size

This commit is contained in:
Daniel Olsen 2021-01-07 12:52:30 +01:00
parent e6d7ca5001
commit a638ba8c6a
4 changed files with 33 additions and 81 deletions

70
Cargo.lock generated
View File

@ -1,26 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "alloc_counter"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a8c3a0a472b3a556e269be64dc65a5c013ba85e940d089367eb8c88f3fdfda9"
dependencies = [
"alloc_counter_macro",
"pin-utils",
]
[[package]]
name = "alloc_counter_macro"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a52f81f9add01deacdc1fcb05ba09523a8faefdec6c3f69cb752b9fa9c22e5a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
@ -58,10 +37,8 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
name = "mercury"
version = "0.1.0"
dependencies = [
"alloc_counter",
"coz",
"rand",
"smallvec",
"tinyvec",
]
@ -71,36 +48,12 @@ version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "proc-macro2"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.0"
@ -141,35 +94,12 @@ dependencies = [
"rand_core",
]
[[package]]
name = "smallvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0"
[[package]]
name = "syn"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "tinyvec"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"

View File

@ -9,13 +9,12 @@ edition = "2018"
[dependencies]
rand = "0.8.0"
coz = "0.1"
smallvec = "1.6.0"
tinyvec = "1.1.0"
#jemallocator = "0.3.2"
#mimalloc = { version = "0.1.22", default-features = false }
alloc_counter = "0.0.4"
#alloc_counter = "0.0.4"
[profile.release]
debug = 1

View File

@ -1,10 +1,26 @@
use std::ops::{Deref, DerefMut};
use rand::prelude::*;
use smallvec::{SmallVec, smallvec};
//use smallvec::{SmallVec, smallvec};
use alloc_counter::{AllocCounterSystem, no_alloc};
#[global_allocator]
static A: AllocCounterSystem = AllocCounterSystem;
//use alloc_counter::{AllocCounterSystem, no_alloc};
//#[global_allocator]
//static A: AllocCounterSystem = AllocCounterSystem;
pub fn size_of_stuff() {
println!("size of azul game: {}", std::mem::size_of::<Game>());
println!("size of azul tile: {}", std::mem::size_of::<Tile>());
println!("size of azul bag: {}", std::mem::size_of::<Bag>());
println!("size of azul market: {}", std::mem::size_of::<Market>());
println!("size of azul factories: {}", std::mem::size_of::<tinyvec::ArrayVec<[Factory; 9]>>());
println!("size of azul factory array: {}", std::mem::size_of::<[Factory; 9]>());
println!("size of azul factory: {}", std::mem::size_of::<Factory>());
println!("size of azul boards: {}", std::mem::size_of::<tinyvec::ArrayVec<[Board; 4]>>());
println!("size of azul board array: {}", std::mem::size_of::<[Board; 4]>());
println!("size of azul board: {}", std::mem::size_of::<Board>());
println!("size of azul option tile: {}", std::mem::size_of::<Option<Tile>>());
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Tile {
@ -193,7 +209,7 @@ impl From<tinyvec::ArrayVec<[Tile; 128]>> for Bag {
#[derive(Default, Debug, Copy)]
struct Factory (tinyvec::ArrayVec<[Tile; 4]>);
impl Clone for Factory {
#[no_alloc]
//#[no_alloc]
fn clone(&self) -> Self {
Factory(self.0.clone())
}
@ -345,6 +361,7 @@ impl Board {
}
}
//#[repr(align(16))]
#[derive(Debug, Clone, Copy)]
pub struct Game {
turn: u32,
@ -430,7 +447,7 @@ impl Game {
}
Ok(())
}
#[no_alloc(forbid)]
// #[no_alloc(forbid)]
pub fn do_move(&mut self, game_move: GameMove) -> Result<(), &'static str> {
let board = &mut self.boards[self.player];
match game_move {
@ -587,7 +604,7 @@ pub fn complicated() -> Result<Game, &'static str> {
#[test]
fn bag() {
let game = Game::new(2, StdRng::seed_from_u64(123)).unwrap();
let game = Game::new(2).unwrap();
let bag = game.bag;
assert_eq!(bag.len(), 100);
@ -621,4 +638,9 @@ fn game_move_iter() {
assert_eq!(i.into_iter().next().unwrap(), GameMove(1, Tile::Blue, 1));
assert_eq!(i.into_iter().count(), 5)
}
#[test]
fn sizes() {
println!("size of azul game: {}", std::mem::size_of::<Game>());
}

View File

@ -8,12 +8,13 @@ use rand::prelude::*;
//#[global_allocator]
//static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
fn main() -> Result<(), &'static str> {
let program = std::env::args().nth(1).expect("no program given")
.parse().unwrap_or(1);
size_of_stuff();
return match program {
1 => {
let mut rng = StdRng::seed_from_u64(42);
@ -28,7 +29,7 @@ fn main() -> Result<(), &'static str> {
game.do_move(GameMove(0, Tile::Black, 4))?;
game.do_move(GameMove(5, Tile::Black, 1))?;
game.do_move(GameMove(0, Tile::Blue, 3))?;
// game.do_move(GameMove(0, Tile::Blue, 3))?;
println!("{:#?}", game);