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

Performance issue #1

Open
Tokenyet opened this issue May 14, 2020 · 1 comment
Open

Performance issue #1

Tokenyet opened this issue May 14, 2020 · 1 comment

Comments

@Tokenyet
Copy link

Tokenyet commented May 14, 2020

image

Recently, I used entitas_ff to play with flame, and I found out that It's expensive to use entitas_ff. According to the observatory, It seems to use too many cpu resource on single get. Is there any way to reduce cpu consumption?

@Tokenyet
Copy link
Author

abstract class Component {}
class AComp extends Component{}
class BComp extends Component{}
class CComp extends Component{}
class DComp extends Component{}
class EComp extends Component{}
class FComp extends Component{}
class GComp extends Component{}
class HComp extends Component{}
class IComp extends Component{}
class JComp extends Component{}

class MeasurementUtil {
  static final Map<String, DateTime> timemap = {};

  static void start(String timeName) {
    timemap[timeName] = DateTime.now();
  }

  static void end(String timeName) {
    if(timemap.containsKey(timeName)) {
      print("$timeName: ${DateTime.now().difference(timemap[timeName]).inMilliseconds} ms");
      timemap.remove(timeName);
    }
  }
}

void main() {
  Map<int, int> value = {
    0: 0,
    1: 1,
    2: 2,
    3: 3,
    4: 4,
    5: 5,
    6: 6,
    7: 7,
    8: 8,
    9: 9,
  };
  
  Map<String, int> sValue = {
    "0": 0,
    "1": 1,
    "2": 2,
    "3": 3,
    "4": 4,
    "5": 5,
    "6": 6,
    "7": 7,
    "8": 8,
    "9": 9,
  };
  Map<Type, int> tvalue = {
    AComp: 0,
    BComp: 1,
    CComp: 2,
    DComp: 3,
    EComp: 4,
    FComp: 5,
    GComp: 6,
    HComp: 7,
    IComp: 8,
    JComp: 9,
  };
  MeasurementUtil.start("int");
  for(int i = 0; i < 1000000;i++) {
    int c = value[0];
  }
  MeasurementUtil.end("int");
  
  MeasurementUtil.start("string");
  for(int i = 0; i < 1000000;i++) {
    int c = sValue[0];
  }
  MeasurementUtil.end("string");
  
  MeasurementUtil.start("type");
  for(int i = 0; i < 1000000;i++) {
    int c = tvalue[GComp];
  }
  MeasurementUtil.end("type");
}
int: 12 ms
string: 9 ms
type: 59 ms

I'm not sure how to optimze, but seems this is the issue of using Type as key.

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

No branches or pull requests

1 participant