-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
358cf04
commit 1aebdc9
Showing
5 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# tekartik strict extension | ||
include: package:tekartik_lints/strict.yaml | ||
include: package:tekartik_lints/strict.yaml | ||
|
||
linter: | ||
rules: | ||
# avoid_print: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:tekartik_app_crypto/src/generate_password.dart'; | ||
|
||
Future<void> main() async { | ||
print(generatePassword()); | ||
stdout.writeln(generatePassword()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import 'package:tekartik_app_crypto/encrypt.dart'; | ||
import 'package:tekartik_common_utils/num_utils.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
class _TestEncrypter { | ||
final String name; | ||
final StringEncrypter encrypter; | ||
_TestEncrypter(this.name, this.encrypter); | ||
} | ||
|
||
class _TestAction { | ||
final String name; | ||
final void Function() action; | ||
_TestAction(this.name, this.action); | ||
} | ||
|
||
String textWithLength(int length) { | ||
return List.generate(length, (i) => i.toString().substring(0, 1)).join(); | ||
} | ||
|
||
void main() { | ||
var password = encryptTextPassword16FromText('password'); | ||
var testEncrypters = [ | ||
_TestEncrypter('aes', aesEncrypterFromPassword(password)), | ||
_TestEncrypter('salsa20', salsa20EncrypterFromPassword(password)), | ||
]; | ||
|
||
group('perf', () { | ||
for (var testEncrypter in testEncrypters) { | ||
var name = testEncrypter.name; | ||
test(name, () { | ||
var encrypter = testEncrypter.encrypter; | ||
for (var data in [ | ||
textWithLength(10), | ||
textWithLength(1000), | ||
textWithLength(10000) | ||
]) { | ||
var encryptedData = encrypter.encrypt(data); | ||
expect(encrypter.decrypt(encryptedData), data); | ||
|
||
var initialEstimationSize = 10; | ||
|
||
int actionsDurationMs(int count, void Function() action) { | ||
var sw = Stopwatch()..start(); | ||
for (var i = 0; i < count; i++) { | ||
action(); | ||
} | ||
sw.stop(); | ||
return sw.elapsedMilliseconds; | ||
} | ||
|
||
void execute(_TestAction testAction) { | ||
void action() { | ||
testAction.action(); | ||
} | ||
|
||
var count = initialEstimationSize; | ||
int ms; | ||
while (true) { | ||
ms = actionsDurationMs(count, action); | ||
// print('count: $count ms: $ms'); | ||
if (ms < 50) { | ||
count = (count * 1.2).toInt(); | ||
} else { | ||
break; | ||
} | ||
} | ||
var countPerMs = count / ms; | ||
var durationTestMs = 500; | ||
var countTest = (countPerMs * durationTestMs).toInt(); | ||
|
||
// print('countTest: $countTest (${(countPerMs * 1000).toInt()} per/s)'); | ||
for (var i = 0; i < 1; i++) { | ||
encryptedData = encrypter.encrypt(data); | ||
|
||
var msTest = actionsDurationMs(countTest, action).boundedMin(1); | ||
countPerMs = countTest / msTest; | ||
print( | ||
'$name ${data.length} ${testAction.name}: (${(countPerMs * 1000).toInt()} per/s)'); | ||
} | ||
} | ||
|
||
execute(_TestAction('encrypt', () { | ||
encrypter.encrypt(data); | ||
})); | ||
execute(_TestAction('decrypt', () { | ||
encrypter.decrypt(encryptedData); | ||
})); | ||
} | ||
}); | ||
} | ||
}); | ||
} |