From edf9b9f161d3036cbadbaa6d15a5a866be80a950 Mon Sep 17 00:00:00 2001 From: hchung Date: Sat, 3 Mar 2018 02:23:24 -0800 Subject: [PATCH 1/2] test caching classids --- src/main/java/opendota/Parse.java | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/opendota/Parse.java b/src/main/java/opendota/Parse.java index 217b413c1..0ff96875b 100644 --- a/src/main/java/opendota/Parse.java +++ b/src/main/java/opendota/Parse.java @@ -104,11 +104,11 @@ public class Entry { public Integer towers_killed; public Integer roshans_killed; public Integer observers_placed; - public Integer draft_order; - public Boolean pick; - public Integer draft_active_team; - public Integer draft_extime0; - public Integer draft_extime1; + public Integer draft_order; + public Boolean pick; + public Integer draft_active_team; + public Integer draft_extime0; + public Integer draft_extime1; public Entry() { } @@ -153,6 +153,8 @@ public UnknownItemFoundException(String message) { private GreevilsGreedVisitor greevilsGreedVisitor; private TrackVisitor trackVisitor; private ArrayList isPlayerStartingItemsWritten; + private int obsClassId = -1; + private int senClassId = -1; //Draft stage variable @@ -723,8 +725,19 @@ public void processEntity(Context ctx, Entity e, boolean entityLeft) //CDOTA_NPC_Observer_Ward_TrueSight //s1 "DT_DOTA_NPC_Observer_Ward" //s1 "DT_DOTA_NPC_Observer_Ward_TrueSight" - boolean isObserver = e.getDtClass().getDtName().equals("CDOTA_NPC_Observer_Ward"); - boolean isSentry = e.getDtClass().getDtName().equals("CDOTA_NPC_Observer_Ward_TrueSight"); + + // Cache the class IDs in a dictionary to avoid repeated string comparisons + String entityName = e.getDtClass().getDtName(); + int entityClassId = e.getDtClass().getClassId(); + if (obsClassId == -1 && entityName.equals("CDOTA_NPC_Observer_Ward")) { + obsClassId = entityClassId; + } + else if (senClassId == -1 && entityName.equals("CDOTA_NPC_Observer_Ward_TrueSight")) { + senClassId = entityClassId; + } + + boolean isObserver = entityClassId == obsClassId; + boolean isSentry = entityClassId == senClassId; if (isObserver || isSentry) { //System.err.println(e); Entry entry = new Entry(time); From de42919fee28a5ea871c3fd4d5d602cbb3f8bb23 Mon Sep 17 00:00:00 2001 From: hchung Date: Sat, 3 Mar 2018 14:47:47 -0800 Subject: [PATCH 2/2] add timing metrics --- src/main/java/opendota/Parse.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/opendota/Parse.java b/src/main/java/opendota/Parse.java index 0ff96875b..fa8f975f4 100644 --- a/src/main/java/opendota/Parse.java +++ b/src/main/java/opendota/Parse.java @@ -155,6 +155,7 @@ public UnknownItemFoundException(String message) { private ArrayList isPlayerStartingItemsWritten; private int obsClassId = -1; private int senClassId = -1; + private long nanoCount = 0; //Draft stage variable @@ -726,18 +727,22 @@ public void processEntity(Context ctx, Entity e, boolean entityLeft) //s1 "DT_DOTA_NPC_Observer_Ward" //s1 "DT_DOTA_NPC_Observer_Ward_TrueSight" - // Cache the class IDs in a dictionary to avoid repeated string comparisons - String entityName = e.getDtClass().getDtName(); + // Cache the class IDs to avoid repeated string comparisons int entityClassId = e.getDtClass().getClassId(); - if (obsClassId == -1 && entityName.equals("CDOTA_NPC_Observer_Ward")) { + if (obsClassId == -1 && e.getDtClass().getDtName().equals("CDOTA_NPC_Observer_Ward")) { obsClassId = entityClassId; } - else if (senClassId == -1 && entityName.equals("CDOTA_NPC_Observer_Ward_TrueSight")) { + else if (senClassId == -1 && e.getDtClass().getDtName().equals("CDOTA_NPC_Observer_Ward_TrueSight")) { senClassId = entityClassId; } + long start = System.nanoTime(); boolean isObserver = entityClassId == obsClassId; boolean isSentry = entityClassId == senClassId; + long end = System.nanoTime(); + nanoCount += (end - start); + System.err.println(nanoCount); + if (isObserver || isSentry) { //System.err.println(e); Entry entry = new Entry(time);