Scala - Enumeration vs. Case-Classes
actor, akka, case-class, enums, scala
Solution
"Don't optimize prematurely" applies. I don't believe difference between them is at all likely to matter, compared to time you spend passing messages to your actor or actually logging them. But I expect the best performance would be to create a Java `enum` (which can be easily accessed and used from Scala) for logging levels instead of Scala `Enumeration`.
Problem
I've created akka actor called LogActor. The LogActors's receive method handling messages from other actors and logging them to the specified log level. I can distinguish between the different levels in 2 ways. The first one: ``` import LogLevel._ object LogLevel extends Enumeration { type LogLevel = Value val Error, Warning, Info, Debug = Value } case class LogMessage(level : LogLevel, msg : String) ``` The second: (EDIT) ``` abstract class LogMessage(msg : String) case class LogMessageError(msg : String) extends LogMessage(msg) case class LogMessageWarning(msg : String) extends LogMessage(msg) case class LogMessageInfo(msg : String) extends LogMessage(msg) case class LogMessageDebug(msg : String) extends LogMessage(msg) ``` Which way is more efficient? does it take less time to match case class or to match enum value? (I read this question but there isn't any answer referring to the runtime issue)