Java - Performance Questions; variable names and file name length

前端 未结 2 1362
执念已碎
执念已碎 2021-01-06 10:11

Well just some questions about performance, but i think some of the questions are logical: - If i use variables with short names will be better/faster to process? Example: \

相关标签:
2条回答
  • 2021-01-06 10:40

    In addition to the excellent answer by Tomasz, you display all the signs of early optimisation. There's several issues:

    1) Until you hit a problem you don't know what to optimise for: reducing CPU usage is a different optimisation from reducing memory or reducing disk usage

    2) Optimisation costs time, which is either your personal time (which has value) or your company's time (which has a more easily equatable value). Optimisation where it is not necessary is a waste of money.

    3) Reducing variable length (even if it did make a difference) would be irrelevant if the important thing to optimise is 'time spent by a programmer to work out what the software does'. Readable code is important - good variable names are an important part of that.

    0 讨论(0)
  • 2021-01-06 10:46

    If i use variables with short names will be better/faster to process?

    No. Variable names might not even be in your resulting bytecode. In the end of the day variables are mapped to registers/stack operands. Variable name is irrelevant. It's only for human beings. And they tend to prefer superPhrase over s.

    if the file name is short will be faster to access it

    No. Files, just like variables, are referenced using special identifiers (e.g. inodes). File name is only needed when opening/locating a file. And it's several orders of magnitude faster compared to actual file access. This applies equally to Java applications and other OS processes.

    0 讨论(0)
提交回复
热议问题