Skip to content

Commit

Permalink
Complete rewrite.
Browse files Browse the repository at this point in the history
  • Loading branch information
dikmax committed Aug 28, 2016
1 parent e23aa26 commit ff33526
Show file tree
Hide file tree
Showing 81 changed files with 19,925 additions and 3,766 deletions.
12 changes: 0 additions & 12 deletions .linter.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ md_proc
[![Build Status](https://travis-ci.org/dikmax/md_proc.svg?branch=master)](https://travis-ci.org/dikmax/md_proc)
[![Coverage Status](https://coveralls.io/repos/dikmax/md_proc/badge.svg?branch=master)](https://coveralls.io/r/dikmax/md_proc?branch=master)
[![Pub](https://img.shields.io/pub/v/md_proc.svg)](https://pub.dartlang.org/packages/md_proc)
[![CommonMark spec](https://img.shields.io/badge/commonmark-0.24-green.svg)](http://spec.commonmark.org/)
[![CommonMark spec](https://img.shields.io/badge/commonmark-0.26-green.svg)](http://spec.commonmark.org/)

[CommonMark]-compliant Markdown parser.

Expand Down
50 changes: 50 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
analyzer:
strong-mode: true

linter:
rules:
- always_declare_return_types
- always_specify_types
- annotate_overrides
- avoid_as
- avoid_empty_else
- avoid_init_to_null
- avoid_return_types_on_setters
- await_only_futures
- camel_case_types
- cancel_subscriptions
- close_sinks
- comment_references
- constant_identifier_names
- control_flow_in_finally
- empty_catches
- empty_constructor_bodies
- empty_statements
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- library_names
- library_prefixes
- list_remove_unrelated_type
- non_constant_identifier_names
- one_member_abstracts
- only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_is_not_empty
- public_member_api_docs
- slash_for_doc_comments
- sort_constructors_first
- sort_unnamed_constructors_first
- super_goes_last
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- type_init_formals
- unawaited_futures
- unnecessary_brace_in_string_interp
- unnecessary_getters_setters
- unrelated_type_equality_checks
- valid_regexps
81 changes: 63 additions & 18 deletions benchmark/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@ import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:md_proc/md_proc.dart';
import 'package:markdown/markdown.dart' as markdown;

class MapEmitter implements ScoreEmitter {
String name;
Map<String, double> scores = <String, double>{};

MapEmitter(this.name);

@override
void emit(String testName, double value) {
scores[testName] = value;
}

double report() {
print("$name: ");
double sum = scores.values.reduce((double v1, double v2) => v1 + v2);
print(" - sum: $sum");
double avg = sum / scores.length;
print(" - avg: $avg");
return avg;
}
}

class MdProcBenchmark extends BenchmarkBase {
String data;

MdProcBenchmark(this.data) : super("md_proc");
MdProcBenchmark(String name, this.data, ScoreEmitter emitter)
: super(name, emitter: emitter);

static void main(String data) {
new MdProcBenchmark(data).report();
static void main(String name, String data, ScoreEmitter emitter) {
new MdProcBenchmark(name, data, emitter).report();
}

// The benchmark code.
Expand All @@ -22,28 +44,51 @@ class MdProcBenchmark extends BenchmarkBase {
class MarkdownBenchmark extends BenchmarkBase {
String data;

MarkdownBenchmark(this.data) : super("markdown");
MarkdownBenchmark(String name, this.data, ScoreEmitter emitter)
: super(name, emitter: emitter);

static void main(String data) {
new MarkdownBenchmark(data).report();
static void main(String name, String data, ScoreEmitter emitter) {
new MarkdownBenchmark(name, data, emitter).report();
}

// The benchmark code.
void run() {
markdown.markdownToHtml(data, extensionSet: markdown.ExtensionSet.commonMark);
markdown.markdownToHtml(data,
extensionSet: markdown.ExtensionSet.commonMark);
}
}

// TODO fix block-ref-flat inline-links-flat performance

main() async {
// Using Pandoc documentation for benchmark
HttpClient client = new HttpClient();
//HttpClientRequest request = await client.getUrl(Uri.parse('https://raw.githubusercontent.com/0xAX/linux-insides/master/mm/linux-mm-2.md'));
//HttpClientRequest request = await client.getUrl(Uri.parse('https://raw.githubusercontent.com/dikmax/dikmax.name/master/post/2014-04-13-vilnius.md'));
//HttpClientRequest request = await client.getUrl(Uri.parse('https://raw.githubusercontent.com/dikmax/md_proc/master/README.md'));
HttpClientRequest request = await client.getUrl(Uri.parse('https://raw.githubusercontent.com/jgm/pandoc/master/README'));
HttpClientResponse response = await request.close();
String data = await response.transform(UTF8.decoder).join();
print("File length: ${data.length}");
MdProcBenchmark.main(data);
MarkdownBenchmark.main(data);
Directory dir = new Directory('benchmark/texts');

MapEmitter mdProcResults = new MapEmitter("md_proc");
MapEmitter markdownResults = new MapEmitter("markdown");

await for (FileSystemEntity entity in dir.list()) {
if (entity is File) {
String name = entity.uri.pathSegments.last;
if (name.endsWith('.md')) {
name = name.replaceAll(new RegExp(r'\.md$'), '');
print('Benchmarking: $name...');
String data = await entity.readAsString();
MdProcBenchmark.main(name, data, mdProcResults);
print('md_proc: ${mdProcResults.scores[name]}');
MarkdownBenchmark.main(name, data, markdownResults);
print('markdown: ${markdownResults.scores[name]}');
}
}
}

double mdProcAvg = mdProcResults.report();
double markdownAvg = markdownResults.report();

if (mdProcAvg < markdownAvg) {
print('md_proc is ${markdownAvg / mdProcAvg} times faster');
} else {
print('md_proc is ${mdProcAvg / markdownAvg} times slover');
}

exit(0);
}

0 comments on commit ff33526

Please sign in to comment.