(self)
| 481 | |
| 482 | @helper.encodeResponse |
| 483 | def actionBenchmark(self): |
| 484 | import sys |
| 485 | import gc |
| 486 | from contextlib import contextmanager |
| 487 | |
| 488 | output = self.sendHeader() |
| 489 | |
| 490 | if "Multiuser" in PluginManager.plugin_manager.plugin_names and not config.multiuser_local: |
| 491 | yield "This function is disabled on this proxy" |
| 492 | return |
| 493 | |
| 494 | @contextmanager |
| 495 | def benchmark(name, standard): |
| 496 | self.log.debug("Benchmark: %s" % name) |
| 497 | s = time.time() |
| 498 | output(b"- %s" % name.encode()) |
| 499 | try: |
| 500 | yield 1 |
| 501 | except Exception as err: |
| 502 | self.log.exception(err) |
| 503 | output(b"<br><b>! Error: %s</b><br>" % Debug.formatException(err).encode()) |
| 504 | taken = time.time() - s |
| 505 | if taken > 0: |
| 506 | multipler = standard / taken |
| 507 | else: |
| 508 | multipler = 99 |
| 509 | if multipler < 0.3: |
| 510 | speed = "Sloooow" |
| 511 | elif multipler < 0.5: |
| 512 | speed = "Ehh" |
| 513 | elif multipler < 0.8: |
| 514 | speed = "Goodish" |
| 515 | elif multipler < 1.2: |
| 516 | speed = "OK" |
| 517 | elif multipler < 1.7: |
| 518 | speed = "Fine" |
| 519 | elif multipler < 2.5: |
| 520 | speed = "Fast" |
| 521 | elif multipler < 3.5: |
| 522 | speed = "WOW" |
| 523 | else: |
| 524 | speed = "Insane!!" |
| 525 | output(b"%.3fs [x%.2f: %s]<br>" % (taken, multipler, speed.encode())) |
| 526 | time.sleep(0.01) |
| 527 | |
| 528 | yield """ |
| 529 | <style> |
| 530 | * { font-family: monospace } |
| 531 | table * { text-align: right; padding: 0px 10px } |
| 532 | </style> |
| 533 | """ |
| 534 | |
| 535 | yield "Benchmarking ZeroNet %s (rev%s) Python %s on: %s...<br>" % (config.version, config.rev, sys.version, sys.platform) |
| 536 | |
| 537 | t = time.time() |
| 538 | |
| 539 | # CryptBitcoin |
| 540 | yield "<br>CryptBitcoin:<br>" |
nothing calls this directly
no test coverage detected